leaflet-city-mapper 0.0.1 → 0.0.3

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 (629) hide show
  1. package/README.md +61 -13
  2. package/cucumber.mjs +4 -0
  3. package/dist/leaflet-city-mapper.js +3 -1
  4. package/dist/leaflet-city-mapper.js.map +4 -4
  5. package/package.json +3 -4
  6. package/src/archives/decodeDirectory.js +32 -0
  7. package/src/archives/decodeHeader.js +19 -0
  8. package/src/archives/decompress.js +5 -0
  9. package/src/archives/getHeader.js +9 -0
  10. package/src/archives/getZxy.js +75 -0
  11. package/src/archives/loadDirectory.js +7 -0
  12. package/src/archives/loadSource.js +17 -0
  13. package/src/archives/read.js +29 -0
  14. package/src/archives/tileId.js +19 -0
  15. package/src/archives/varint.js +15 -0
  16. package/src/camera/angles.js +6 -0
  17. package/src/camera/animationPoint.js +8 -0
  18. package/src/camera/cameraMapReady.js +8 -0
  19. package/src/camera/cancelCameraAnimation.js +11 -0
  20. package/src/camera/cleanupCameraMap.js +11 -0
  21. package/src/camera/constrainCameraToBounds.js +3 -0
  22. package/src/camera/displayPoint.js +3 -0
  23. package/src/camera/fitCameraBounds.js +48 -0
  24. package/src/camera/groundBounds.js +11 -0
  25. package/src/camera/initializeCameraMap.js +25 -0
  26. package/src/camera/mapAnimateCamera.js +17 -0
  27. package/src/camera/mapCamera.js +123 -0
  28. package/src/camera/mapContainerPointToLayerPoint.js +7 -0
  29. package/src/camera/mapGetBearing.js +1 -0
  30. package/src/camera/mapGetBounds.js +14 -0
  31. package/src/camera/mapGetBoundsCenterZoom.js +7 -0
  32. package/src/camera/mapGetBoundsZoom.js +14 -0
  33. package/src/camera/mapGetCenterLayerPoint.js +5 -0
  34. package/src/camera/mapGetPitch.js +1 -0
  35. package/src/camera/mapLayerPointToContainerPoint.js +7 -0
  36. package/src/camera/mapLimitCenter.js +12 -0
  37. package/src/camera/mapLimitOffset.js +10 -0
  38. package/src/camera/mapPanBy.js +9 -0
  39. package/src/camera/mapPanInside.js +14 -0
  40. package/src/camera/mapResetNorth.js +1 -0
  41. package/src/camera/mapResetNorthPitch.js +1 -0
  42. package/src/camera/mapSetBearing.js +1 -0
  43. package/src/camera/mapSetPitch.js +1 -0
  44. package/src/camera/mapSetPitchAndBearing.js +14 -0
  45. package/src/camera/mapSetZoomAround.js +11 -0
  46. package/src/camera/mapStopPitchBearingAnimation.js +6 -0
  47. package/src/camera/mapTryAnimatedPan.js +9 -0
  48. package/src/camera/mapUpdateCameraOverlays.js +7 -0
  49. package/src/camera/pointOf.js +3 -0
  50. package/src/camera/project.js +20 -0
  51. package/src/camera/runCameraAnimations.js +28 -0
  52. package/src/camera/scheduleCameraAnimation.js +8 -0
  53. package/src/camera/updateSky.js +16 -0
  54. package/src/camera/verticalGroundY.js +4 -0
  55. package/src/collision/collectMeshes.js +5 -0
  56. package/src/collision/collider.js +63 -0
  57. package/src/collision/horizontalRay.js +12 -0
  58. package/src/collision/intersectMeshes.js +133 -0
  59. package/src/collision/sortHits.js +23 -0
  60. package/src/constants/CELL.js +4 -0
  61. package/src/constants/Compass.js +7 -0
  62. package/src/constants/ContainerResize.js +7 -0
  63. package/src/constants/HEIGHT.js +1 -0
  64. package/src/constants/PitchDrag.js +7 -0
  65. package/src/constants/ShiftRotate.js +7 -0
  66. package/src/constants/TILE_RADIUS.js +1 -0
  67. package/src/constants/TILE_SIZE.js +1 -0
  68. package/src/constants/TouchMode.js +6 -0
  69. package/src/constants/accessorSizes.js +1 -0
  70. package/src/constants/accessorTypes.js +8 -0
  71. package/src/constants/attachState.js +1 -0
  72. package/src/constants/cameraControlsState.js +1 -0
  73. package/src/constants/cityMapper.js +6 -0
  74. package/src/constants/colliders.js +2 -0
  75. package/src/constants/dark.js +1 -0
  76. package/src/constants/elevationWGSL.js +27 -0
  77. package/src/constants/glass.js +1 -0
  78. package/src/constants/headlight.js +1 -0
  79. package/src/constants/hull.js +1 -0
  80. package/src/constants/indexState.js +1 -0
  81. package/src/constants/limbs.js +9 -0
  82. package/src/constants/mapCameraState.js +1 -0
  83. package/src/constants/moves.js +11 -0
  84. package/src/constants/nativeEventMaps.js +1 -0
  85. package/src/constants/nativeLayerState.js +1 -0
  86. package/src/constants/nativeMethodHandlers.js +31 -0
  87. package/src/constants/onMapChangeState.js +1 -0
  88. package/src/constants/onZoomAnimState.js +1 -0
  89. package/src/constants/paints.js +10 -0
  90. package/src/constants/parts.js +19 -0
  91. package/src/constants/pendingUpdates.js +1 -0
  92. package/src/constants/pumpState.js +1 -0
  93. package/src/constants/renderers.js +2 -0
  94. package/src/constants/ringDirections.js +10 -0
  95. package/src/constants/roundProfile.js +1 -0
  96. package/src/constants/shirt.js +1 -0
  97. package/src/constants/skin.js +2 -0
  98. package/src/constants/speed.js +3 -0
  99. package/src/constants/taillight.js +1 -0
  100. package/src/constants/trafficShader.js +49 -0
  101. package/src/constants/trousers.js +1 -0
  102. package/src/constants/tyre.js +1 -0
  103. package/src/constants/underEntryState.js +1 -0
  104. package/src/constants/vehicles.js +40 -0
  105. package/src/constants/white.js +1 -0
  106. package/src/controls/acceptPitchDrag.js +4 -0
  107. package/src/controls/acceptRotateDrag.js +3 -0
  108. package/src/controls/adjustCameraDrag.js +10 -0
  109. package/src/controls/cameraControls.js +60 -0
  110. package/src/controls/cameraDragClick.js +9 -0
  111. package/src/controls/cameraDragContextMenu.js +8 -0
  112. package/src/controls/cameraDragDown.js +20 -0
  113. package/src/controls/cameraDragEnd.js +6 -0
  114. package/src/controls/cameraDragMove.js +23 -0
  115. package/src/controls/changeCameraTouch.js +14 -0
  116. package/src/controls/cleanupCameraTouch.js +24 -0
  117. package/src/controls/compassAddHooks.js +15 -0
  118. package/src/controls/compassOrientation.js +6 -0
  119. package/src/controls/compassRemoveHooks.js +5 -0
  120. package/src/controls/containerResizeAddHooks.js +8 -0
  121. package/src/controls/containerResizeRemoveHooks.js +5 -0
  122. package/src/controls/dragCamera.js +22 -0
  123. package/src/controls/editable.js +3 -0
  124. package/src/controls/endAllCameraDrags.js +7 -0
  125. package/src/controls/endAllCameraTouches.js +7 -0
  126. package/src/controls/endCameraTouch.js +11 -0
  127. package/src/controls/endCameraTouchEvent.js +5 -0
  128. package/src/controls/finishCameraDrag.js +9 -0
  129. package/src/controls/finishCompassPermission.js +16 -0
  130. package/src/controls/loadCameraControls.js +9 -0
  131. package/src/controls/moveCameraTouch.js +22 -0
  132. package/src/controls/notifyCameraTouchChange.js +1 -0
  133. package/src/controls/pitchDragAddHooks.js +6 -0
  134. package/src/controls/pitchDragRemoveHooks.js +5 -0
  135. package/src/controls/refreshRotateControl.js +7 -0
  136. package/src/controls/refreshRotateFocus.js +5 -0
  137. package/src/controls/removeCameraDrag.js +23 -0
  138. package/src/controls/resizeMap.js +3 -0
  139. package/src/controls/rotateButtonClick.js +7 -0
  140. package/src/controls/rotateButtonKeydown.js +11 -0
  141. package/src/controls/rotateControl.js +3 -0
  142. package/src/controls/rotateOnAdd.js +38 -0
  143. package/src/controls/rotateOnRemove.js +6 -0
  144. package/src/controls/shiftRotateAddHooks.js +8 -0
  145. package/src/controls/shiftRotateRemoveHooks.js +5 -0
  146. package/src/controls/shiftRotateWheel.js +9 -0
  147. package/src/controls/startCameraTouch.js +23 -0
  148. package/src/core/addImageState.js +7 -0
  149. package/src/core/addRasterImage.js +10 -0
  150. package/src/core/adjustCameraMarkerPan.js +22 -0
  151. package/src/core/beforeNativeRender.js +10 -0
  152. package/src/core/boundsQuad.js +11 -0
  153. package/src/core/bringNativeLayerToBack.js +3 -0
  154. package/src/core/bringNativeLayerToFront.js +3 -0
  155. package/src/core/cameraCircleBounds.js +6 -0
  156. package/src/core/cameraMarkerDrag.js +18 -0
  157. package/src/core/cameraMarkerOnDrag.js +8 -0
  158. package/src/core/cancelGridFade.js +10 -0
  159. package/src/core/closestCameraLayerPoint.js +7 -0
  160. package/src/core/compareNativeHits.js +3 -0
  161. package/src/core/current.js +3 -0
  162. package/src/core/disposeNativeLayer.js +35 -0
  163. package/src/core/fireRasterLoad.js +5 -0
  164. package/src/core/forwardNativeError.js +3 -0
  165. package/src/core/gridlayerGetEvents.js +7 -0
  166. package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
  167. package/src/core/handleNativeMapEvent.js +47 -0
  168. package/src/core/hideTargets.js +16 -0
  169. package/src/core/initNativeGPU.js +21 -0
  170. package/src/core/initializeGridContainer.js +6 -0
  171. package/src/core/initializeNativeLayer.js +42 -0
  172. package/src/core/localPixel.js +5 -0
  173. package/src/core/localPixelForGeometry.js +6 -0
  174. package/src/core/localPosition.js +6 -0
  175. package/src/core/markerCameraIconPoint.js +9 -0
  176. package/src/core/markerGetEvents.js +5 -0
  177. package/src/core/markerInitInteraction.js +8 -0
  178. package/src/core/markerQuadCorners.js +31 -0
  179. package/src/core/markerSetIcon.js +9 -0
  180. package/src/core/markerSetPos.js +14 -0
  181. package/src/core/markerSetRotation.js +7 -0
  182. package/src/core/markerUpdateZIndex.js +8 -0
  183. package/src/core/nativeAddLatLng.js +3 -0
  184. package/src/core/nativeBringToBack.js +3 -0
  185. package/src/core/nativeBringToFront.js +3 -0
  186. package/src/core/nativeEvents.js +26 -0
  187. package/src/core/nativeImageError.js +8 -0
  188. package/src/core/nativeImageRefresh.js +7 -0
  189. package/src/core/nativeLayer.js +97 -0
  190. package/src/core/nativeLayerMethod.js +21 -0
  191. package/src/core/nativeRedraw.js +3 -0
  192. package/src/core/nativeSetBounds.js +3 -0
  193. package/src/core/nativeSetIcon.js +3 -0
  194. package/src/core/nativeSetLatLng.js +3 -0
  195. package/src/core/nativeSetLatLngs.js +3 -0
  196. package/src/core/nativeSetOpacity.js +3 -0
  197. package/src/core/nativeSetRadius.js +3 -0
  198. package/src/core/nativeSetStyle.js +3 -0
  199. package/src/core/nativeSetUrl.js +3 -0
  200. package/src/core/nativeSetZIndex.js +3 -0
  201. package/src/core/nativeSetZIndexOffset.js +3 -0
  202. package/src/core/popupAdjustPan.js +23 -0
  203. package/src/core/popupGetEvents.js +5 -0
  204. package/src/core/popupUpdatePosition.js +14 -0
  205. package/src/core/putNativeMesh.js +33 -0
  206. package/src/core/quadNativeMesh.js +15 -0
  207. package/src/core/readyNativeGPU.js +6 -0
  208. package/src/core/refreshNativeEvent.js +5 -0
  209. package/src/core/refreshNativeLayer.js +29 -0
  210. package/src/core/refreshNativeLayerContract.js +3 -0
  211. package/src/core/rejectNativeReady.js +3 -0
  212. package/src/core/removeImageState.js +8 -0
  213. package/src/core/removeNativeEvents.js +16 -0
  214. package/src/core/removeTargets.js +8 -0
  215. package/src/core/reorderNativeLayer.js +6 -0
  216. package/src/core/resolveNativeReady.js +3 -0
  217. package/src/core/restoreNativeEvents.js +6 -0
  218. package/src/core/runGridFades.js +14 -0
  219. package/src/core/runMarkerPanFrame.js +12 -0
  220. package/src/core/scheduleGridFade.js +9 -0
  221. package/src/core/scheduleMarkerPan.js +8 -0
  222. package/src/core/styleNativeMesh.js +10 -0
  223. package/src/core/syncGridLayer.js +22 -0
  224. package/src/core/syncImageOverlay.js +9 -0
  225. package/src/core/syncMarker.js +12 -0
  226. package/src/core/syncVectorLayer.js +26 -0
  227. package/src/core/synchronizeNativeLayer.js +35 -0
  228. package/src/core/textureFor.js +48 -0
  229. package/src/core/tooltipGetEvents.js +5 -0
  230. package/src/core/tooltipSetPosition.js +8 -0
  231. package/src/core/updateGridOpacity.js +23 -0
  232. package/src/core/updateNativeLayerView.js +6 -0
  233. package/src/core/uploadCanvasTexture.js +19 -0
  234. package/src/geometry/addBridges.js +88 -0
  235. package/src/geometry/below.js +3 -0
  236. package/src/geometry/box.js +3 -0
  237. package/src/geometry/bridgeElevation.js +19 -0
  238. package/src/geometry/bridgeLocal.js +4 -0
  239. package/src/geometry/build.js +19 -0
  240. package/src/geometry/circleAt.js +5 -0
  241. package/src/geometry/clipLine.js +23 -0
  242. package/src/geometry/clipSegment.js +19 -0
  243. package/src/geometry/computeBounds.js +33 -0
  244. package/src/geometry/conformModelToTerrain.js +67 -0
  245. package/src/geometry/cross.js +3 -0
  246. package/src/geometry/disk.js +11 -0
  247. package/src/geometry/diskAt.js +4 -0
  248. package/src/geometry/dot.js +6 -0
  249. package/src/geometry/emitter.js +8 -0
  250. package/src/geometry/lampPostGeometry.js +24 -0
  251. package/src/geometry/lampRing.js +11 -0
  252. package/src/geometry/lightGeometry.js +15 -0
  253. package/src/geometry/line.js +54 -0
  254. package/src/geometry/nativeGeometry.js +55 -0
  255. package/src/geometry/nativeTriangle.js +3 -0
  256. package/src/geometry/polygon.js +22 -0
  257. package/src/geometry/push.js +3 -0
  258. package/src/geometry/quad.js +4 -0
  259. package/src/geometry/roofCoverage.js +52 -0
  260. package/src/geometry/samePoint.js +3 -0
  261. package/src/geometry/segment.js +21 -0
  262. package/src/geometry/setVertexColor.js +15 -0
  263. package/src/geometry/sub.js +6 -0
  264. package/src/geometry/surface.js +17 -0
  265. package/src/geometry/treeGeometry.js +31 -0
  266. package/src/geometry/treeRing.js +14 -0
  267. package/src/geometry/triangle.js +12 -0
  268. package/src/geometry/vertexNormals.js +32 -0
  269. package/src/geometry/visit.js +9 -0
  270. package/src/index.js +98 -65
  271. package/src/lighting/cacheLightGrid.js +23 -0
  272. package/src/lighting/collectLightMeshes.js +6 -0
  273. package/src/lighting/lightGrid.js +42 -0
  274. package/src/lighting/updatePointLights.js +34 -0
  275. package/src/lighting/visitCells.js +15 -0
  276. package/src/lighting/worldLights.js +27 -0
  277. package/src/models/decodeModel.js +45 -0
  278. package/src/models/hasUnsupportedPrimitives.js +10 -0
  279. package/src/models/loadBuffer.js +6 -0
  280. package/src/models/loadImage.js +15 -0
  281. package/src/models/loadModel.js +69 -0
  282. package/src/models/materialFor.js +21 -0
  283. package/src/models/modelNode.js +93 -0
  284. package/src/models/nodeMatrix.js +22 -0
  285. package/src/models/readAccessor.js +53 -0
  286. package/src/models/readAccessorValues.js +16 -0
  287. package/src/models/textureFor.js +35 -0
  288. package/src/models/textureSampler.js +10 -0
  289. package/src/picking/collectVisibleMesh.js +4 -0
  290. package/src/picking/findFeature.js +49 -0
  291. package/src/picking/hit.js +23 -0
  292. package/src/picking/hitMesh.js +30 -0
  293. package/src/picking/onClick.js +13 -0
  294. package/src/picking/onPointerLeave.js +11 -0
  295. package/src/picking/onPointerMove.js +15 -0
  296. package/src/picking/pointerClick.js +5 -0
  297. package/src/picking/pointerLeave.js +5 -0
  298. package/src/picking/pointerMove.js +5 -0
  299. package/src/picking/raycast.js +59 -0
  300. package/src/picking/setHighlight.js +13 -0
  301. package/src/picking/shouldSkipOther.js +3 -0
  302. package/src/picking/showFeature.js +34 -0
  303. package/src/raster/addRasterTile.js +114 -0
  304. package/src/raster/comparePendingTiles.js +5 -0
  305. package/src/raster/createGeometry.js +22 -0
  306. package/src/raster/createRasterMesh.js +47 -0
  307. package/src/raster/finishAttachment.js +11 -0
  308. package/src/raster/finishRasterTile.js +47 -0
  309. package/src/raster/getRasterEvents.js +6 -0
  310. package/src/raster/getRasterTileSize.js +5 -0
  311. package/src/raster/initRaster.js +38 -0
  312. package/src/raster/isLoading.js +5 -0
  313. package/src/raster/loadRasterTile.js +10 -0
  314. package/src/raster/onPMTileAdd.js +10 -0
  315. package/src/raster/onPMTileRemove.js +8 -0
  316. package/src/raster/pruneRasterTiles.js +37 -0
  317. package/src/raster/pumpRasterTiles.js +22 -0
  318. package/src/raster/readyRaster.js +13 -0
  319. package/src/raster/registerTerrainTile.js +12 -0
  320. package/src/raster/releaseRasterTile.js +18 -0
  321. package/src/raster/releaseRasterTiles.js +15 -0
  322. package/src/raster/removeRasterTile.js +13 -0
  323. package/src/raster/reportError.js +6 -0
  324. package/src/raster/setPMTileOpacity.js +7 -0
  325. package/src/raster/setPMTileZIndex.js +7 -0
  326. package/src/raster/setRasterOpacity.js +11 -0
  327. package/src/raster/setRasterTerrain.js +21 -0
  328. package/src/raster/setRasterZIndex.js +11 -0
  329. package/src/raster/updateAttachedTiles.js +10 -0
  330. package/src/raster/updateRasterTiles.js +59 -0
  331. package/src/rendering/collectFrameMeshes.js +31 -0
  332. package/src/rendering/collectMeshes.js +36 -0
  333. package/src/rendering/compareMeshes.js +10 -0
  334. package/src/rendering/compareRoofTiles.js +4 -0
  335. package/src/rendering/composeRoofAtlas.js +52 -0
  336. package/src/rendering/createMesh.js +33 -0
  337. package/src/rendering/createProgram.js +92 -0
  338. package/src/rendering/destroyAfterSubmission.js +8 -0
  339. package/src/rendering/destroyTexture.js +6 -0
  340. package/src/rendering/disposeMesh.js +14 -0
  341. package/src/rendering/drawGeometry.js +129 -0
  342. package/src/rendering/drawSceneMeshes.js +51 -0
  343. package/src/rendering/ensureRoofBlit.js +40 -0
  344. package/src/rendering/prepareFrameMeshes.js +42 -0
  345. package/src/rendering/prepareFrameUniforms.js +49 -0
  346. package/src/rendering/rebuildRoofAtlas.js +67 -0
  347. package/src/rendering/render.js +57 -0
  348. package/src/rendering/reportCompilation.js +17 -0
  349. package/src/rendering/resizeRenderer.js +19 -0
  350. package/src/rendering/sortMeshes.js +6 -0
  351. package/src/rendering/synchronizeZoomView.js +34 -0
  352. package/src/rendering/textureBinding.js +7 -0
  353. package/src/rendering/updateMapCamera.js +32 -0
  354. package/src/rendering/updateRoofRaster.js +32 -0
  355. package/src/scene/attach.js +161 -0
  356. package/src/scene/attachLayer.js +10 -0
  357. package/src/scene/cancelUpdate.js +10 -0
  358. package/src/scene/emptyEvents.js +3 -0
  359. package/src/scene/emptyNode.js +11 -0
  360. package/src/scene/endZoom.js +16 -0
  361. package/src/scene/failAttachment.js +9 -0
  362. package/src/scene/get3DEvents.js +13 -0
  363. package/src/scene/init3D.js +30 -0
  364. package/src/scene/initializeLayer.js +16 -0
  365. package/src/scene/initializerFor.js +14 -0
  366. package/src/scene/layerInitialize.js +38 -0
  367. package/src/scene/layerLayerAdd.js +21 -0
  368. package/src/scene/onAdd3DLayer.js +35 -0
  369. package/src/scene/onMapChange.js +16 -0
  370. package/src/scene/onRemove3DLayer.js +69 -0
  371. package/src/scene/onZoomAnim.js +16 -0
  372. package/src/scene/placeEntry.js +11 -0
  373. package/src/scene/placeUnderEntry.js +8 -0
  374. package/src/scene/ready3D.js +25 -0
  375. package/src/scene/releaseRenderer.js +14 -0
  376. package/src/scene/removeEntry.js +6 -0
  377. package/src/scene/renderPendingMapChange.js +11 -0
  378. package/src/scene/renderPendingUpdates.js +19 -0
  379. package/src/scene/renderPendingZoomAnimation.js +7 -0
  380. package/src/scene/rendererDeviceError.js +10 -0
  381. package/src/scene/rendererDeviceLost.js +11 -0
  382. package/src/scene/replaceEntry.js +7 -0
  383. package/src/scene/reportError.js +3 -0
  384. package/src/scene/requestAdapter.js +12 -0
  385. package/src/scene/requestDevice.js +9 -0
  386. package/src/scene/resolveNextInitialization.js +12 -0
  387. package/src/scene/restoreObject.js +71 -0
  388. package/src/scene/runPlacements.js +7 -0
  389. package/src/scene/setParent.js +7 -0
  390. package/src/scene/showWebGPUWarning.js +16 -0
  391. package/src/scene/startZoom.js +5 -0
  392. package/src/scene/traverse.js +7 -0
  393. package/src/scene/underEntry.js +17 -0
  394. package/src/scene/update.js +19 -0
  395. package/src/scene/updateCamera.js +34 -0
  396. package/src/scene/updateWorldMatrix.js +48 -0
  397. package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
  398. package/src/shadows/bindSunlight.js +12 -0
  399. package/src/shadows/drawShadowMeshes.js +48 -0
  400. package/src/shadows/ensureShadowPipeline.js +53 -0
  401. package/src/shadows/renderSunlight.js +46 -0
  402. package/src/shadows/resizeSunlight.js +15 -0
  403. package/src/shadows/shadowBounds.js +32 -0
  404. package/src/shadows/shadowCacheMatches.js +23 -0
  405. package/src/shadows/shadowMatrix.js +39 -0
  406. package/src/sources/addGeneratedTriangle.js +6 -0
  407. package/src/sources/addTriangle.js +17 -0
  408. package/src/sources/attachAreaMesh.js +58 -0
  409. package/src/sources/buildArea.js +42 -0
  410. package/src/sources/buildAreaFeature.js +41 -0
  411. package/src/sources/buildAreaPoint.js +25 -0
  412. package/src/sources/buildAreaPolygon.js +29 -0
  413. package/src/sources/compareAreaDistance.js +4 -0
  414. package/src/sources/generateTreeGeometry.js +11 -0
  415. package/src/sources/groundOffset.js +3 -0
  416. package/src/sources/initializeGeoJSON.js +8 -0
  417. package/src/sources/instanceAreaGeometry.js +29 -0
  418. package/src/sources/projectRing.js +20 -0
  419. package/src/sources/projectedTree.js +13 -0
  420. package/src/sources/pump.js +54 -0
  421. package/src/sources/releaseArea.js +22 -0
  422. package/src/sources/setGeoJSONData.js +12 -0
  423. package/src/sources/setGeoJSONLayerData.js +5 -0
  424. package/src/sources/sourceAreaContext.js +9 -0
  425. package/src/sources/updateArea.js +45 -0
  426. package/src/sources/updateStatus.js +12 -0
  427. package/src/sunlight/addTimeLayer.js +3 -0
  428. package/src/sunlight/addTo.js +10 -0
  429. package/src/sunlight/atmosphere.js +28 -0
  430. package/src/sunlight/horizontalPosition.js +16 -0
  431. package/src/sunlight/initSunlight.js +14 -0
  432. package/src/sunlight/initialize.js +11 -0
  433. package/src/sunlight/mix.js +6 -0
  434. package/src/sunlight/moonPosition.js +17 -0
  435. package/src/sunlight/onAdd.js +5 -0
  436. package/src/sunlight/onAddSun.js +66 -0
  437. package/src/sunlight/projectCelestialBody.js +13 -0
  438. package/src/sunlight/remove.js +7 -0
  439. package/src/sunlight/removeSun.js +15 -0
  440. package/src/sunlight/removeTimeLayer.js +3 -0
  441. package/src/sunlight/render.js +7 -0
  442. package/src/sunlight/rgb.js +6 -0
  443. package/src/sunlight/solarPosition.js +17 -0
  444. package/src/sunlight/styleTimeControl.js +7 -0
  445. package/src/sunlight/tickSun.js +5 -0
  446. package/src/sunlight/updateSky.js +20 -0
  447. package/src/sunlight/updateSun.js +34 -0
  448. package/src/sunlight/useLiveTime.js +6 -0
  449. package/src/sunlight/useSelectedTime.js +20 -0
  450. package/src/terrain/clearLayerTerrain.js +5 -0
  451. package/src/terrain/getElevation.js +10 -0
  452. package/src/terrain/initTerrain.js +20 -0
  453. package/src/terrain/loadReadyTerrain.js +5 -0
  454. package/src/terrain/loadTerrain.js +63 -0
  455. package/src/terrain/loadTerrainTiles.js +13 -0
  456. package/src/terrain/onTerrainAdd.js +21 -0
  457. package/src/terrain/onTerrainChange.js +14 -0
  458. package/src/terrain/onTerrainRemove.js +41 -0
  459. package/src/terrain/readBridges.js +4 -0
  460. package/src/terrain/sample.js +7 -0
  461. package/src/terrain/setLayerTerrain.js +5 -0
  462. package/src/terrain/setTerrainHeight.js +10 -0
  463. package/src/terrain/terrainAtlas.js +23 -0
  464. package/src/terrain/terrainElevation.js +20 -0
  465. package/src/terrain/terrainGrid.js +24 -0
  466. package/src/traffic/addTraffic.js +7 -0
  467. package/src/traffic/along.js +14 -0
  468. package/src/traffic/clockMinutes.js +6 -0
  469. package/src/traffic/compareDepartures.js +5 -0
  470. package/src/traffic/createTrafficMesh.js +7 -0
  471. package/src/traffic/destroyTrafficGpu.js +5 -0
  472. package/src/traffic/disposeTrafficObject.js +13 -0
  473. package/src/traffic/drawTrafficRoute.js +6 -0
  474. package/src/traffic/failTraffic.js +6 -0
  475. package/src/traffic/failedTrafficLoad.js +5 -0
  476. package/src/traffic/fetchTrafficLanes.js +10 -0
  477. package/src/traffic/groundTraffic.js +15 -0
  478. package/src/traffic/initTraffic.js +54 -0
  479. package/src/traffic/loadTraffic.js +15 -0
  480. package/src/traffic/loadedTrafficLanes.js +16 -0
  481. package/src/traffic/locateTraffic.js +9 -0
  482. package/src/traffic/moveTraffic.js +15 -0
  483. package/src/traffic/placeTraffic.js +21 -0
  484. package/src/traffic/prepareTraffic.js +25 -0
  485. package/src/traffic/readyTraffic.js +6 -0
  486. package/src/traffic/rebaseTraffic.js +58 -0
  487. package/src/traffic/rebuildTrafficMesh.js +28 -0
  488. package/src/traffic/removeTraffic.js +17 -0
  489. package/src/traffic/routeColor.js +6 -0
  490. package/src/traffic/routeGeometry.js +31 -0
  491. package/src/traffic/scheduledTrips.js +40 -0
  492. package/src/traffic/startTraffic.js +8 -0
  493. package/src/traffic/tickTraffic.js +57 -0
  494. package/src/traffic/toLanes.js +16 -0
  495. package/src/traffic/tooltip.js +11 -0
  496. package/src/traffic/trafficBounds.js +17 -0
  497. package/src/traffic/trafficNow.js +4 -0
  498. package/src/traffic/trafficStorage.js +5 -0
  499. package/src/traffic/tripsAt.js +27 -0
  500. package/src/traffic/updateTraffic.js +8 -0
  501. package/src/traffic/updateTrafficTerrain.js +12 -0
  502. package/src/traffic/vehicleOffsets.js +11 -0
  503. package/src/triangulation/area.js +9 -0
  504. package/src/triangulation/clean.js +18 -0
  505. package/src/triangulation/containsVertex.js +11 -0
  506. package/src/triangulation/cross.js +3 -0
  507. package/src/triangulation/crossesBoundary.js +8 -0
  508. package/src/triangulation/crossesRing.js +9 -0
  509. package/src/triangulation/equal.js +3 -0
  510. package/src/triangulation/inside.js +10 -0
  511. package/src/triangulation/insideHole.js +7 -0
  512. package/src/triangulation/intersects.js +11 -0
  513. package/src/triangulation/isClockWise.js +13 -0
  514. package/src/triangulation/minimumX.js +6 -0
  515. package/src/triangulation/on.js +4 -0
  516. package/src/triangulation/sortHoles.js +26 -0
  517. package/src/triangulation/triangulate.js +86 -0
  518. package/src/utils/channel.js +4 -0
  519. package/src/utils/compareDistance.js +3 -0
  520. package/src/utils/noOperation.js +1 -0
  521. package/src/utils/parseColor.js +42 -0
  522. package/src/utils/toSRGB.js +3 -0
  523. package/src/utils/wrap.js +3 -0
  524. package/src/vehicles/bicycleModel.js +23 -0
  525. package/src/vehicles/boatBenches.js +8 -0
  526. package/src/vehicles/boatModel.js +27 -0
  527. package/src/vehicles/busModel.js +6 -0
  528. package/src/vehicles/carModel.js +22 -0
  529. package/src/vehicles/carriage.js +19 -0
  530. package/src/vehicles/metroModel.js +9 -0
  531. package/src/vehicles/mirror.js +8 -0
  532. package/src/vehicles/pedestrianModel.js +17 -0
  533. package/src/vehicles/tramModel.js +9 -0
  534. package/src/walk/blocked.js +6 -0
  535. package/src/walk/createWalk.js +60 -0
  536. package/src/walk/initWalk.js +18 -0
  537. package/src/walk/initialize.js +6 -0
  538. package/src/walk/local.js +10 -0
  539. package/src/walk/onAdd.js +4 -0
  540. package/src/walk/onBlur.js +3 -0
  541. package/src/walk/onKey.js +12 -0
  542. package/src/walk/onPointer.js +13 -0
  543. package/src/walk/onRemove.js +4 -0
  544. package/src/walk/onTerrain.js +5 -0
  545. package/src/walk/place.js +18 -0
  546. package/src/walk/start.js +37 -0
  547. package/src/walk/step.js +53 -0
  548. package/src/walk/stop.js +27 -0
  549. package/src/walk/toggle.js +6 -0
  550. package/dist/scene/gpu.js +0 -3
  551. package/dist/scene/gpu.js.map +0 -7
  552. package/dist/scene/lighting.js +0 -9
  553. package/dist/scene/lighting.js.map +0 -7
  554. package/dist/scene/model.js +0 -2
  555. package/dist/scene/model.js.map +0 -7
  556. package/dist/scene/picking.js +0 -2
  557. package/dist/scene/picking.js.map +0 -7
  558. package/dist/scene/pmtiles.js +0 -2
  559. package/dist/scene/pmtiles.js.map +0 -7
  560. package/dist/scene/render.js +0 -15
  561. package/dist/scene/render.js.map +0 -7
  562. package/dist/scene/sources.js +0 -2
  563. package/dist/scene/sources.js.map +0 -7
  564. package/dist/types/3d.js +0 -2
  565. package/dist/types/3d.js.map +0 -7
  566. package/dist/types/geojson.js +0 -2
  567. package/dist/types/geojson.js.map +0 -7
  568. package/dist/types/pmtiles.js +0 -2
  569. package/dist/types/pmtiles.js.map +0 -7
  570. package/dist/types/sunlight.js +0 -2
  571. package/dist/types/sunlight.js.map +0 -7
  572. package/dist/types/terrain.js +0 -24
  573. package/dist/types/terrain.js.map +0 -7
  574. package/dist/types/traffic.js +0 -41
  575. package/dist/types/traffic.js.map +0 -7
  576. package/dist/types/walk.js +0 -2
  577. package/dist/types/walk.js.map +0 -7
  578. package/dist/utils/control.js +0 -2
  579. package/dist/utils/control.js.map +0 -7
  580. package/dist/utils/geometry.js +0 -2
  581. package/dist/utils/geometry.js.map +0 -7
  582. package/dist/utils/lighting.js +0 -2
  583. package/dist/utils/lighting.js.map +0 -7
  584. package/dist/utils/model.js +0 -2
  585. package/dist/utils/model.js.map +0 -7
  586. package/dist/utils/picking.js +0 -2
  587. package/dist/utils/picking.js.map +0 -7
  588. package/dist/utils/pmtiles.js +0 -2
  589. package/dist/utils/pmtiles.js.map +0 -7
  590. package/dist/utils/scene.js +0 -2
  591. package/dist/utils/scene.js.map +0 -7
  592. package/dist/utils/shaders.js +0 -203
  593. package/dist/utils/shaders.js.map +0 -7
  594. package/dist/utils/sun.js +0 -2
  595. package/dist/utils/sun.js.map +0 -7
  596. package/dist/utils/terrain.js +0 -2
  597. package/dist/utils/terrain.js.map +0 -7
  598. package/dist/utils/traffic.js +0 -2
  599. package/dist/utils/traffic.js.map +0 -7
  600. package/dist/utils/vehicles.js +0 -2
  601. package/dist/utils/vehicles.js.map +0 -7
  602. package/dist/utils/walk.js +0 -2
  603. package/dist/utils/walk.js.map +0 -7
  604. package/src/scene/gpu.js +0 -438
  605. package/src/scene/lighting.js +0 -193
  606. package/src/scene/model.js +0 -204
  607. package/src/scene/picking.js +0 -150
  608. package/src/scene/pmtiles.js +0 -94
  609. package/src/scene/render.js +0 -467
  610. package/src/scene/sources.js +0 -265
  611. package/src/types/3d.js +0 -337
  612. package/src/types/geojson.js +0 -42
  613. package/src/types/pmtiles.js +0 -143
  614. package/src/types/sunlight.js +0 -142
  615. package/src/types/terrain.js +0 -331
  616. package/src/types/traffic.js +0 -356
  617. package/src/types/walk.js +0 -219
  618. package/src/utils/control.js +0 -18
  619. package/src/utils/geometry.js +0 -256
  620. package/src/utils/lighting.js +0 -51
  621. package/src/utils/model.js +0 -178
  622. package/src/utils/picking.js +0 -119
  623. package/src/utils/pmtiles.js +0 -79
  624. package/src/utils/scene.js +0 -102
  625. package/src/utils/sun.js +0 -71
  626. package/src/utils/terrain.js +0 -78
  627. package/src/utils/traffic.js +0 -90
  628. package/src/utils/vehicles.js +0 -69
  629. package/src/utils/walk.js +0 -72
@@ -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
- }
@@ -1,90 +0,0 @@
1
- // Pure helpers of the 'traffic' type: lane interpolation and vehicle scheduling.
2
-
3
- /** Default urban speed (m/s) used to turn a lane's hourly `flow` into vehicles on the road. */
4
- export const speed = 8;
5
-
6
- /** Evenly spaced starting offsets (metres) for `flow` vehicles/h moving at `velocity` m/s on a `length` metres lane. */
7
- export function vehicleOffsets(length, flow, velocity = speed) {
8
- const count = Math.round(length * flow / 3600 / velocity);
9
- return Array.from({ length: count }, (_, i) => (i + 0.5) * length / count);
10
- }
11
-
12
- /** Point and unit direction at distance `s` along `points` ([x, z, y?]) with cumulative `lengths`. */
13
- export function along(points, lengths, s) {
14
- let i = 1;
15
- while (i < lengths.length - 1 && lengths[i] < s) i++;
16
- const a = points[i - 1], b = points[i], d = lengths[i] - lengths[i - 1] || 1;
17
- const t = (s - lengths[i - 1]) / d;
18
- return { x: a[0] + (b[0] - a[0]) * t, y: (a[2] ?? 0) + ((b[2] ?? 0) - (a[2] ?? 0)) * t, z: a[1] + (b[1] - a[1]) * t, dx: (b[0] - a[0]) / d, dz: (b[1] - a[1]) / d };
19
- }
20
-
21
- /**
22
- * Trips of a frequency-based timetable (like GTFS frequencies.txt) underway at `date`, in the timetable's local time.
23
- * @param {{timeZone: string, duration: number, services: Array<{from: string, to: string, every?: number, months?: number[], weekdays?: number[]}>}} timetable
24
- * `duration` and `every` are minutes; `from`/`to` are 'HH:MM' first/last departures; months are 1-12, weekdays 0 (Sunday)-6.
25
- * @returns {Array<{id: string, departure: string, progress: number}>} `progress` is 0-1 along the lane.
26
- */
27
- export function scheduledTrips(date, { timeZone, duration, services }) {
28
- const time = new Date(date);
29
- if (!Number.isFinite(time.getTime())) throw new Error('Invalid date');
30
- const clock = new Intl.DateTimeFormat('en-GB', {
31
- timeZone, year: 'numeric', month: '2-digit', day: '2-digit',
32
- hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23',
33
- });
34
- const parts = Object.fromEntries(clock.formatToParts(time).filter(p => p.type !== 'literal').map(p => [p.type, Number(p.value)]));
35
- const minute = parts.hour * 60 + parts.minute + (parts.second + time.getUTCMilliseconds() / 1000) / 60;
36
- const weekday = new Date(Date.UTC(parts.year, parts.month - 1, parts.day)).getUTCDay();
37
- const minutes = clockTime => clockTime.split(':').reduce((hours, value) => hours * 60 + Number(value));
38
- const departures = [];
39
- for (const { from, to, every = Infinity, months, weekdays } of services) {
40
- if (months?.includes(parts.month) === false || weekdays?.includes(weekday) === false) continue;
41
- for (let departure = minutes(from); departure <= minutes(to); departure += every) departures.push(departure);
42
- }
43
- return departures.sort((a, b) => a - b).filter(departure => minute >= departure && minute < departure + duration).map(departure => ({
44
- id: `${parts.year}-${parts.month}-${parts.day}-${departure}`,
45
- departure: `${String(Math.floor(departure / 60)).padStart(2, '0')}:${String(departure % 60).padStart(2, '0')}`,
46
- progress: (minute - departure) / duration,
47
- }));
48
- }
49
-
50
- // GeoJSON (Multi)LineStrings become lanes ({latlngs, properties, elevation?}); prepare() adds `points` ([x, z, ground]),
51
- // `lengths` and `length` in layer-local metres.
52
- export const toLanes = ({ features = [] }) => features.flatMap(({ geometry, properties }) => {
53
- const lines = geometry?.type === 'LineString' ? [geometry.coordinates] : geometry?.type === 'MultiLineString' ? geometry.coordinates : [];
54
- return lines.map(line => ({ latlngs: line.map(([lng, lat]) => [lat, lng]), properties: properties ?? {}, elevation: properties?.elevation }));
55
- });
56
-
57
- // A lane with a `timetable` runs scheduled trips end to end; one with a `flow` (vehicles/h) loops evenly spaced vehicles.
58
- export const tripsAt = (time, lanes, velocity) => lanes.flatMap((lane, l) => {
59
- const { timetable, flow = 0 } = lane.properties;
60
- if (!lane.length) return [];
61
- if (timetable) return scheduledTrips(time, timetable).map(trip => ({
62
- id: `${l}-${trip.id}`, lane, distance: trip.progress * lane.length, speed: lane.length / (timetable.duration * 60),
63
- properties: { ...lane.properties, departure: trip.departure },
64
- }));
65
- const travelled = time / 1000 * velocity;
66
- return (lane.offsets ||= vehicleOffsets(lane.length, flow, velocity))
67
- .map((offset, k) => ({ id: `${l}-${k}`, lane, distance: (offset + travelled) % lane.length, speed: velocity, properties: lane.properties }));
68
- });
69
-
70
- /** Dashed lane outline, in layer-local metres. */
71
- export function routeGeometry(lanes) {
72
- const position = [], normal = [], color = [];
73
- for (const { points, lengths } of lanes) for (let i = 1; i < points.length; i++) {
74
- const a = points[i - 1], b = points[i];
75
- const dx = b[0] - a[0], dz = b[1] - a[1], length = lengths[i] - lengths[i - 1];
76
- if (!length) continue;
77
- const x = -dz / length * 2.5, z = dx / length * 2.5;
78
- for (let distance = Math.floor(lengths[i - 1] / 30) * 30; distance < lengths[i]; distance += 30) {
79
- const start = Math.max(0, (distance - lengths[i - 1]) / length);
80
- const end = Math.min(1, (distance + 18 - lengths[i - 1]) / length);
81
- if (end <= start) continue;
82
- const p = [a[0] + dx * start, a[1] + dz * start], q = [a[0] + dx * end, a[1] + dz * end], y = a[2] + 0.4;
83
- for (const point of [[p[0] - x, p[1] - z], [p[0] + x, p[1] + z], [q[0] + x, q[1] + z],
84
- [p[0] - x, p[1] - z], [q[0] + x, q[1] + z], [q[0] - x, q[1] - z]]) {
85
- position.push(point[0], y, point[1]); normal.push(0, 1, 0); color.push(0.08, 0.7, 0.85);
86
- }
87
- }
88
- }
89
- return { position, normal, color };
90
- }
@@ -1,69 +0,0 @@
1
- // Built-in vehicles for the 'traffic' type. Models are [ring of [x, z], bottom, top, rgb, topRing?] convex prisms in metres;
2
- // forward is -z, right is +x. `topRing` (same length as `ring`) tapers the prism; rgb components above 1 are self-lit lamps.
3
- const paints = [[0.86, 0.86, 0.88], [0.1, 0.1, 0.12], [0.5, 0.53, 0.57], [0.65, 0.1, 0.08], [0.12, 0.25, 0.55], [0.85, 0.7, 0.15]];
4
- export const box = (x0, x1, z0, z1) => [[x0, z0], [x1, z0], [x1, z1], [x0, z1]];
5
- const mirror = (x0, x1, z0, z1, ...rest) => [[box(x0, x1, z0, z1), ...rest], [box(-x1, -x0, z0, z1), ...rest]];
6
- const glass = [0.12, 0.15, 0.18], tyre = [0.05, 0.05, 0.05];
7
- const headlight = [1.9, 1.85, 1.7], taillight = [1.7, 0.06, 0.05];
8
- const car = i => {
9
- const paint = paints[i % paints.length];
10
- return [
11
- ...mirror(0.7, 0.92, -1.68, -1.02, 0, 0.64, tyre),
12
- ...mirror(0.7, 0.92, 1.02, 1.68, 0, 0.64, tyre),
13
- [[[-0.9, -1.95], [-0.72, -2.25], [0.72, -2.25], [0.9, -1.95], [0.9, 2.05], [0.76, 2.25], [-0.76, 2.25], [-0.9, 2.05]],
14
- 0.28, 0.82, paint],
15
- // Greenhouse: the windscreen leans back, the rear window less.
16
- [box(-0.84, 0.84, -0.75, 1.6), 0.82, 1.38, glass, box(-0.7, 0.7, -0.05, 1.3)],
17
- [box(-0.71, 0.71, -0.06, 1.31), 1.38, 1.46, paint],
18
- ...mirror(0.38, 0.8, -2.3, -2.16, 0.56, 0.76, headlight),
19
- [box(-0.78, 0.78, 2.16, 2.3), 0.6, 0.76, taillight],
20
- ];
21
- };
22
- // Panoramic river cruiser, about 60 × 11 m: glass saloon, open upper deck with benches, wheelhouse forward.
23
- const white = [0.92, 0.93, 0.92], hull = [[-5.5, 30], [5.5, 30], [5.5, -20], [4, -26], [1.5, -30], [-1.5, -30], [-4, -26], [-5.5, -20]];
24
- const boat = () => [
25
- [hull, 0, 0.8, [0.1, 0.16, 0.26]],
26
- [hull, 0.8, 1.4, white],
27
- [box(-5, 5, -18, 26), 1.4, 3.7, glass, box(-4.6, 4.6, -17.4, 25.6)],
28
- ...mirror(4.64, 4.74, -17, 25, 3.25, 3.45, [1.6, 1.25, 0.8]),
29
- [box(-4.8, 4.8, -17.8, 25.8), 3.7, 3.9, white],
30
- ...Array.from({ length: 12 }, (_, i) => mirror(0.5, 3.8, -12 + i * 3, -11.3 + i * 3, 3.9, 4.4, [0.62, 0.1, 0.1])).flat(),
31
- ...mirror(4.65, 4.8, -13.6, 25.8, 3.9, 4.8, white),
32
- [box(-4.8, 4.8, 25.65, 25.8), 3.9, 4.8, white],
33
- [box(-2.2, 2.2, -17.6, -14), 3.9, 4.7, white],
34
- [box(-2.2, 2.2, -17.6, -14), 4.7, 5.5, glass],
35
- [box(-2.5, 2.5, -18, -13.6), 5.5, 5.7, white],
36
- [box(-2.45, -2.2, -16.2, -15.8), 5, 5.3, [2, 0.15, 0.1]],
37
- [box(2.2, 2.45, -16.2, -15.8), 5, 5.3, [0.1, 2, 0.4]],
38
- [box(-0.1, 0.1, -15.9, -15.7), 5.7, 6.6, white],
39
- [box(-0.15, 0.15, -15.95, -15.65), 6.6, 6.8, [2, 2, 1.9]],
40
- ];
41
-
42
- export const build = parts => {
43
- const position = [], normal = [], color = [];
44
- const triangle = (a, b, c, tint) => {
45
- const u = b.map((v, i) => v - a[i]), v = c.map((w, i) => w - a[i]);
46
- 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]], length = Math.hypot(...n);
47
- for (const point of [a, b, c]) { position.push(...point); normal.push(...n.map(w => w / length)); color.push(...tint); }
48
- };
49
- for (const [ring, bottom, top, tint, topRing = ring] of parts) {
50
- const low = ring.map(([x, z]) => [x, bottom, z]), high = topRing.map(([x, z]) => [x, top, z]);
51
- for (let i = 0; i < ring.length; i++) {
52
- const j = (i + 1) % ring.length;
53
- triangle(low[i], low[j], high[j], tint); triangle(low[i], high[j], high[i], tint);
54
- }
55
- for (let i = 1; i < ring.length - 1; i++) {
56
- triangle(high[0], high[i], high[i + 1], tint); triangle(low[0], low[i + 1], low[i], tint);
57
- }
58
- }
59
- return { position, normal, color };
60
- };
61
-
62
- /**
63
- * `side`: default offset (metres) to the right of the lane centreline. `model(i)` gives the prisms of the i-th vehicle.
64
- * `lights`: night point lights in model space (see the night lighting grid), e.g. the pool cast by the headlights.
65
- */
66
- export const vehicles = {
67
- car: { side: 1.8, model: car, lights: [{ position: [0, 1.2, -6], radius: 10, color: [1, 0.94, 0.82], flux: 800 }] },
68
- boat: { side: 0, model: boat, lights: [{ position: [0, 8, 4], radius: 30, color: [1, 0.8, 0.55], flux: 20000 }] },
69
- };
package/src/utils/walk.js DELETED
@@ -1,72 +0,0 @@
1
- import { box } from './vehicles.js';
2
-
3
- // Pedestrian, about 1.77 m tall, prisms as in utils/vehicles.js (forward -z). Limbs hang from their pivot at y = 0.
4
- const skin = [0.85, 0.64, 0.5], shirt = [0.75, 0.2, 0.15], trousers = [0.16, 0.2, 0.32], dark = [0.08, 0.07, 0.06];
5
- export const parts = {
6
- body: [
7
- [box(-0.17, 0.17, -0.1, 0.1), 0.82, 0.95, trousers],
8
- [box(-0.19, 0.19, -0.11, 0.11), 0.95, 1.44, shirt],
9
- [box(-0.05, 0.05, -0.05, 0.05), 1.44, 1.5, skin],
10
- [box(-0.1, 0.1, -0.11, 0.1), 1.5, 1.72, skin],
11
- [box(-0.105, 0.105, -0.06, 0.115), 1.58, 1.77, dark],
12
- [box(-0.105, 0.105, -0.115, -0.06), 1.7, 1.77, dark],
13
- ],
14
- leg: [[box(-0.07, 0.07, -0.07, 0.07), -0.82, 0, trousers], [box(-0.07, 0.07, -0.17, 0.07), -0.9, -0.82, dark]],
15
- arm: [[box(-0.05, 0.05, -0.05, 0.05), -0.55, 0, shirt], [box(-0.045, 0.045, -0.045, 0.045), -0.66, -0.55, skin]],
16
- };
17
- // [part, pivot x, pivot y, swing sign]
18
- export const limbs = [['body', 0, 0, 0], ['leg', -0.09, 0.9, 1], ['leg', 0.09, 0.9, -1], ['arm', -0.25, 1.42, -1], ['arm', 0.25, 1.42, 1]];
19
- // Walls (non-horizontal triangles) of a mesh in world space, bucketed by 8 m cells; `origin` is the world translation
20
- // at build time, since layer roots only move vertically with the terrain afterwards.
21
- export const CELL = 8;
22
- const colliders = new WeakMap();
23
- export function collider(mesh) {
24
- let c = colliders.get(mesh.geometry);
25
- if (c) return c;
26
- const m = mesh.worldMatrix, { position: { data: p }, index, normal, uv } = mesh.geometry.attributes;
27
- const count = index ? index.count : p.length / 3, tri = [], nrm = [], cells = new Map(), v = [];
28
- for (let i = 0; i < count; i += 3) {
29
- const first = index ? index.data[i] : i;
30
- // Streetlight halos (uv.x <= 2, see scene/picking.js) are light, not matter.
31
- if (mesh.program.nightLight && uv && uv.data[first * 2] <= 2) continue;
32
- for (let k = 0; k < 3; k++) {
33
- const j = (index ? index.data[i + k] : i + k) * 3, x = p[j], y = p[j + 1], z = p[j + 2];
34
- v[k * 3] = m[0] * x + m[4] * y + m[8] * z + m[12];
35
- v[k * 3 + 1] = m[1] * x + m[5] * y + m[9] * z + m[13];
36
- v[k * 3 + 2] = m[2] * x + m[6] * y + m[10] * z + m[14];
37
- }
38
- const ex = v[3] - v[0], ey = v[4] - v[1], ez = v[5] - v[2], fx = v[6] - v[0], fy = v[7] - v[1], fz = v[8] - v[2];
39
- let nx = ey * fz - ez * fy, nz = ex * fy - ey * fx;
40
- const ny = ez * fx - ex * fz, length = Math.hypot(nx, ny, nz);
41
- if (!length || Math.abs(ny) > 0.9 * length) continue;
42
- if (normal) {
43
- // The stored normal tells the outside, whatever the winding.
44
- const j = first * 3, a = normal.data;
45
- if ((m[0] * a[j] + m[4] * a[j + 1] + m[8] * a[j + 2]) * nx + (m[2] * a[j] + m[6] * a[j + 1] + m[10] * a[j + 2]) * nz < 0) { nx = -nx; nz = -nz; }
46
- }
47
- const h = Math.hypot(nx, nz), t = nrm.length / 2;
48
- tri.push(...v); nrm.push(nx / h, nz / h);
49
- for (let ix = Math.floor(Math.min(v[0], v[3], v[6]) / CELL); ix <= Math.floor(Math.max(v[0], v[3], v[6]) / CELL); ix++)
50
- for (let iz = Math.floor(Math.min(v[2], v[5], v[8]) / CELL); iz <= Math.floor(Math.max(v[2], v[5], v[8]) / CELL); iz++) {
51
- const key = ix + ',' + iz;
52
- if (!cells.has(key)) cells.set(key, []);
53
- cells.get(key).push(t);
54
- }
55
- }
56
- c = { tri: Float32Array.from(tri), nrm: Float32Array.from(nrm), cells, origin: [m[12], m[13], m[14]] };
57
- colliders.set(mesh.geometry, c);
58
- return c;
59
- }
60
-
61
- // Möller-Trumbore for the horizontal ray (ox, oy, oz) + d·(dx, 0, dz) against triangle t; returns d or -1.
62
- export function horizontalRay(v, t, ox, oy, oz, dx, dz) {
63
- const i = t * 9, ex = v[i + 3] - v[i], ey = v[i + 4] - v[i + 1], ez = v[i + 5] - v[i + 2];
64
- const fx = v[i + 6] - v[i], fy = v[i + 7] - v[i + 1], fz = v[i + 8] - v[i + 2];
65
- const px = -dz * fy, py = dz * fx - dx * fz, pz = dx * fy, det = ex * px + ey * py + ez * pz;
66
- if (Math.abs(det) < 1e-9) return -1;
67
- const tx = ox - v[i], ty = oy - v[i + 1], tz = oz - v[i + 2], u = (tx * px + ty * py + tz * pz) / det;
68
- if (u < 0 || u > 1) return -1;
69
- const qx = ty * ez - tz * ey, qy = tz * ex - tx * ez, qz = tx * ey - ty * ex, w = (dx * qx + dz * qz) / det;
70
- if (w < 0 || u + w > 1) return -1;
71
- return (fx * qx + fy * qy + fz * qz) / det;
72
- }