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.
- package/README.md +61 -13
- package/cucumber.mjs +4 -0
- package/dist/leaflet-city-mapper.js +3 -1
- package/dist/leaflet-city-mapper.js.map +4 -4
- package/package.json +3 -4
- package/src/archives/decodeDirectory.js +32 -0
- package/src/archives/decodeHeader.js +19 -0
- package/src/archives/decompress.js +5 -0
- package/src/archives/getHeader.js +9 -0
- package/src/archives/getZxy.js +75 -0
- package/src/archives/loadDirectory.js +7 -0
- package/src/archives/loadSource.js +17 -0
- package/src/archives/read.js +29 -0
- package/src/archives/tileId.js +19 -0
- package/src/archives/varint.js +15 -0
- package/src/camera/angles.js +6 -0
- package/src/camera/animationPoint.js +8 -0
- package/src/camera/cameraMapReady.js +8 -0
- package/src/camera/cancelCameraAnimation.js +11 -0
- package/src/camera/cleanupCameraMap.js +11 -0
- package/src/camera/constrainCameraToBounds.js +3 -0
- package/src/camera/displayPoint.js +3 -0
- package/src/camera/fitCameraBounds.js +48 -0
- package/src/camera/groundBounds.js +11 -0
- package/src/camera/initializeCameraMap.js +25 -0
- package/src/camera/mapAnimateCamera.js +17 -0
- package/src/camera/mapCamera.js +123 -0
- package/src/camera/mapContainerPointToLayerPoint.js +7 -0
- package/src/camera/mapGetBearing.js +1 -0
- package/src/camera/mapGetBounds.js +14 -0
- package/src/camera/mapGetBoundsCenterZoom.js +7 -0
- package/src/camera/mapGetBoundsZoom.js +14 -0
- package/src/camera/mapGetCenterLayerPoint.js +5 -0
- package/src/camera/mapGetPitch.js +1 -0
- package/src/camera/mapLayerPointToContainerPoint.js +7 -0
- package/src/camera/mapLimitCenter.js +12 -0
- package/src/camera/mapLimitOffset.js +10 -0
- package/src/camera/mapPanBy.js +9 -0
- package/src/camera/mapPanInside.js +14 -0
- package/src/camera/mapResetNorth.js +1 -0
- package/src/camera/mapResetNorthPitch.js +1 -0
- package/src/camera/mapSetBearing.js +1 -0
- package/src/camera/mapSetPitch.js +1 -0
- package/src/camera/mapSetPitchAndBearing.js +14 -0
- package/src/camera/mapSetZoomAround.js +11 -0
- package/src/camera/mapStopPitchBearingAnimation.js +6 -0
- package/src/camera/mapTryAnimatedPan.js +9 -0
- package/src/camera/mapUpdateCameraOverlays.js +7 -0
- package/src/camera/pointOf.js +3 -0
- package/src/camera/project.js +20 -0
- package/src/camera/runCameraAnimations.js +28 -0
- package/src/camera/scheduleCameraAnimation.js +8 -0
- package/src/camera/updateSky.js +16 -0
- package/src/camera/verticalGroundY.js +4 -0
- package/src/collision/collectMeshes.js +5 -0
- package/src/collision/collider.js +63 -0
- package/src/collision/horizontalRay.js +12 -0
- package/src/collision/intersectMeshes.js +133 -0
- package/src/collision/sortHits.js +23 -0
- package/src/constants/CELL.js +4 -0
- package/src/constants/Compass.js +7 -0
- package/src/constants/ContainerResize.js +7 -0
- package/src/constants/HEIGHT.js +1 -0
- package/src/constants/PitchDrag.js +7 -0
- package/src/constants/ShiftRotate.js +7 -0
- package/src/constants/TILE_RADIUS.js +1 -0
- package/src/constants/TILE_SIZE.js +1 -0
- package/src/constants/TouchMode.js +6 -0
- package/src/constants/accessorSizes.js +1 -0
- package/src/constants/accessorTypes.js +8 -0
- package/src/constants/attachState.js +1 -0
- package/src/constants/cameraControlsState.js +1 -0
- package/src/constants/cityMapper.js +6 -0
- package/src/constants/colliders.js +2 -0
- package/src/constants/dark.js +1 -0
- package/src/constants/elevationWGSL.js +27 -0
- package/src/constants/glass.js +1 -0
- package/src/constants/headlight.js +1 -0
- package/src/constants/hull.js +1 -0
- package/src/constants/indexState.js +1 -0
- package/src/constants/limbs.js +9 -0
- package/src/constants/mapCameraState.js +1 -0
- package/src/constants/moves.js +11 -0
- package/src/constants/nativeEventMaps.js +1 -0
- package/src/constants/nativeLayerState.js +1 -0
- package/src/constants/nativeMethodHandlers.js +31 -0
- package/src/constants/onMapChangeState.js +1 -0
- package/src/constants/onZoomAnimState.js +1 -0
- package/src/constants/paints.js +10 -0
- package/src/constants/parts.js +19 -0
- package/src/constants/pendingUpdates.js +1 -0
- package/src/constants/pumpState.js +1 -0
- package/src/constants/renderers.js +2 -0
- package/src/constants/ringDirections.js +10 -0
- package/src/constants/roundProfile.js +1 -0
- package/src/constants/shirt.js +1 -0
- package/src/constants/skin.js +2 -0
- package/src/constants/speed.js +3 -0
- package/src/constants/taillight.js +1 -0
- package/src/constants/trafficShader.js +49 -0
- package/src/constants/trousers.js +1 -0
- package/src/constants/tyre.js +1 -0
- package/src/constants/underEntryState.js +1 -0
- package/src/constants/vehicles.js +40 -0
- package/src/constants/white.js +1 -0
- package/src/controls/acceptPitchDrag.js +4 -0
- package/src/controls/acceptRotateDrag.js +3 -0
- package/src/controls/adjustCameraDrag.js +10 -0
- package/src/controls/cameraControls.js +60 -0
- package/src/controls/cameraDragClick.js +9 -0
- package/src/controls/cameraDragContextMenu.js +8 -0
- package/src/controls/cameraDragDown.js +20 -0
- package/src/controls/cameraDragEnd.js +6 -0
- package/src/controls/cameraDragMove.js +23 -0
- package/src/controls/changeCameraTouch.js +14 -0
- package/src/controls/cleanupCameraTouch.js +24 -0
- package/src/controls/compassAddHooks.js +15 -0
- package/src/controls/compassOrientation.js +6 -0
- package/src/controls/compassRemoveHooks.js +5 -0
- package/src/controls/containerResizeAddHooks.js +8 -0
- package/src/controls/containerResizeRemoveHooks.js +5 -0
- package/src/controls/dragCamera.js +22 -0
- package/src/controls/editable.js +3 -0
- package/src/controls/endAllCameraDrags.js +7 -0
- package/src/controls/endAllCameraTouches.js +7 -0
- package/src/controls/endCameraTouch.js +11 -0
- package/src/controls/endCameraTouchEvent.js +5 -0
- package/src/controls/finishCameraDrag.js +9 -0
- package/src/controls/finishCompassPermission.js +16 -0
- package/src/controls/loadCameraControls.js +9 -0
- package/src/controls/moveCameraTouch.js +22 -0
- package/src/controls/notifyCameraTouchChange.js +1 -0
- package/src/controls/pitchDragAddHooks.js +6 -0
- package/src/controls/pitchDragRemoveHooks.js +5 -0
- package/src/controls/refreshRotateControl.js +7 -0
- package/src/controls/refreshRotateFocus.js +5 -0
- package/src/controls/removeCameraDrag.js +23 -0
- package/src/controls/resizeMap.js +3 -0
- package/src/controls/rotateButtonClick.js +7 -0
- package/src/controls/rotateButtonKeydown.js +11 -0
- package/src/controls/rotateControl.js +3 -0
- package/src/controls/rotateOnAdd.js +38 -0
- package/src/controls/rotateOnRemove.js +6 -0
- package/src/controls/shiftRotateAddHooks.js +8 -0
- package/src/controls/shiftRotateRemoveHooks.js +5 -0
- package/src/controls/shiftRotateWheel.js +9 -0
- package/src/controls/startCameraTouch.js +23 -0
- package/src/core/addImageState.js +7 -0
- package/src/core/addRasterImage.js +10 -0
- package/src/core/adjustCameraMarkerPan.js +22 -0
- package/src/core/beforeNativeRender.js +10 -0
- package/src/core/boundsQuad.js +11 -0
- package/src/core/bringNativeLayerToBack.js +3 -0
- package/src/core/bringNativeLayerToFront.js +3 -0
- package/src/core/cameraCircleBounds.js +6 -0
- package/src/core/cameraMarkerDrag.js +18 -0
- package/src/core/cameraMarkerOnDrag.js +8 -0
- package/src/core/cancelGridFade.js +10 -0
- package/src/core/closestCameraLayerPoint.js +7 -0
- package/src/core/compareNativeHits.js +3 -0
- package/src/core/current.js +3 -0
- package/src/core/disposeNativeLayer.js +35 -0
- package/src/core/fireRasterLoad.js +5 -0
- package/src/core/forwardNativeError.js +3 -0
- package/src/core/gridlayerGetEvents.js +7 -0
- package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
- package/src/core/handleNativeMapEvent.js +47 -0
- package/src/core/hideTargets.js +16 -0
- package/src/core/initNativeGPU.js +21 -0
- package/src/core/initializeGridContainer.js +6 -0
- package/src/core/initializeNativeLayer.js +42 -0
- package/src/core/localPixel.js +5 -0
- package/src/core/localPixelForGeometry.js +6 -0
- package/src/core/localPosition.js +6 -0
- package/src/core/markerCameraIconPoint.js +9 -0
- package/src/core/markerGetEvents.js +5 -0
- package/src/core/markerInitInteraction.js +8 -0
- package/src/core/markerQuadCorners.js +31 -0
- package/src/core/markerSetIcon.js +9 -0
- package/src/core/markerSetPos.js +14 -0
- package/src/core/markerSetRotation.js +7 -0
- package/src/core/markerUpdateZIndex.js +8 -0
- package/src/core/nativeAddLatLng.js +3 -0
- package/src/core/nativeBringToBack.js +3 -0
- package/src/core/nativeBringToFront.js +3 -0
- package/src/core/nativeEvents.js +26 -0
- package/src/core/nativeImageError.js +8 -0
- package/src/core/nativeImageRefresh.js +7 -0
- package/src/core/nativeLayer.js +97 -0
- package/src/core/nativeLayerMethod.js +21 -0
- package/src/core/nativeRedraw.js +3 -0
- package/src/core/nativeSetBounds.js +3 -0
- package/src/core/nativeSetIcon.js +3 -0
- package/src/core/nativeSetLatLng.js +3 -0
- package/src/core/nativeSetLatLngs.js +3 -0
- package/src/core/nativeSetOpacity.js +3 -0
- package/src/core/nativeSetRadius.js +3 -0
- package/src/core/nativeSetStyle.js +3 -0
- package/src/core/nativeSetUrl.js +3 -0
- package/src/core/nativeSetZIndex.js +3 -0
- package/src/core/nativeSetZIndexOffset.js +3 -0
- package/src/core/popupAdjustPan.js +23 -0
- package/src/core/popupGetEvents.js +5 -0
- package/src/core/popupUpdatePosition.js +14 -0
- package/src/core/putNativeMesh.js +33 -0
- package/src/core/quadNativeMesh.js +15 -0
- package/src/core/readyNativeGPU.js +6 -0
- package/src/core/refreshNativeEvent.js +5 -0
- package/src/core/refreshNativeLayer.js +29 -0
- package/src/core/refreshNativeLayerContract.js +3 -0
- package/src/core/rejectNativeReady.js +3 -0
- package/src/core/removeImageState.js +8 -0
- package/src/core/removeNativeEvents.js +16 -0
- package/src/core/removeTargets.js +8 -0
- package/src/core/reorderNativeLayer.js +6 -0
- package/src/core/resolveNativeReady.js +3 -0
- package/src/core/restoreNativeEvents.js +6 -0
- package/src/core/runGridFades.js +14 -0
- package/src/core/runMarkerPanFrame.js +12 -0
- package/src/core/scheduleGridFade.js +9 -0
- package/src/core/scheduleMarkerPan.js +8 -0
- package/src/core/styleNativeMesh.js +10 -0
- package/src/core/syncGridLayer.js +22 -0
- package/src/core/syncImageOverlay.js +9 -0
- package/src/core/syncMarker.js +12 -0
- package/src/core/syncVectorLayer.js +26 -0
- package/src/core/synchronizeNativeLayer.js +35 -0
- package/src/core/textureFor.js +48 -0
- package/src/core/tooltipGetEvents.js +5 -0
- package/src/core/tooltipSetPosition.js +8 -0
- package/src/core/updateGridOpacity.js +23 -0
- package/src/core/updateNativeLayerView.js +6 -0
- package/src/core/uploadCanvasTexture.js +19 -0
- package/src/geometry/addBridges.js +88 -0
- package/src/geometry/below.js +3 -0
- package/src/geometry/box.js +3 -0
- package/src/geometry/bridgeElevation.js +19 -0
- package/src/geometry/bridgeLocal.js +4 -0
- package/src/geometry/build.js +19 -0
- package/src/geometry/circleAt.js +5 -0
- package/src/geometry/clipLine.js +23 -0
- package/src/geometry/clipSegment.js +19 -0
- package/src/geometry/computeBounds.js +33 -0
- package/src/geometry/conformModelToTerrain.js +67 -0
- package/src/geometry/cross.js +3 -0
- package/src/geometry/disk.js +11 -0
- package/src/geometry/diskAt.js +4 -0
- package/src/geometry/dot.js +6 -0
- package/src/geometry/emitter.js +8 -0
- package/src/geometry/lampPostGeometry.js +24 -0
- package/src/geometry/lampRing.js +11 -0
- package/src/geometry/lightGeometry.js +15 -0
- package/src/geometry/line.js +54 -0
- package/src/geometry/nativeGeometry.js +55 -0
- package/src/geometry/nativeTriangle.js +3 -0
- package/src/geometry/polygon.js +22 -0
- package/src/geometry/push.js +3 -0
- package/src/geometry/quad.js +4 -0
- package/src/geometry/roofCoverage.js +52 -0
- package/src/geometry/samePoint.js +3 -0
- package/src/geometry/segment.js +21 -0
- package/src/geometry/setVertexColor.js +15 -0
- package/src/geometry/sub.js +6 -0
- package/src/geometry/surface.js +17 -0
- package/src/geometry/treeGeometry.js +31 -0
- package/src/geometry/treeRing.js +14 -0
- package/src/geometry/triangle.js +12 -0
- package/src/geometry/vertexNormals.js +32 -0
- package/src/geometry/visit.js +9 -0
- package/src/index.js +98 -65
- package/src/lighting/cacheLightGrid.js +23 -0
- package/src/lighting/collectLightMeshes.js +6 -0
- package/src/lighting/lightGrid.js +42 -0
- package/src/lighting/updatePointLights.js +34 -0
- package/src/lighting/visitCells.js +15 -0
- package/src/lighting/worldLights.js +27 -0
- package/src/models/decodeModel.js +45 -0
- package/src/models/hasUnsupportedPrimitives.js +10 -0
- package/src/models/loadBuffer.js +6 -0
- package/src/models/loadImage.js +15 -0
- package/src/models/loadModel.js +69 -0
- package/src/models/materialFor.js +21 -0
- package/src/models/modelNode.js +93 -0
- package/src/models/nodeMatrix.js +22 -0
- package/src/models/readAccessor.js +53 -0
- package/src/models/readAccessorValues.js +16 -0
- package/src/models/textureFor.js +35 -0
- package/src/models/textureSampler.js +10 -0
- package/src/picking/collectVisibleMesh.js +4 -0
- package/src/picking/findFeature.js +49 -0
- package/src/picking/hit.js +23 -0
- package/src/picking/hitMesh.js +30 -0
- package/src/picking/onClick.js +13 -0
- package/src/picking/onPointerLeave.js +11 -0
- package/src/picking/onPointerMove.js +15 -0
- package/src/picking/pointerClick.js +5 -0
- package/src/picking/pointerLeave.js +5 -0
- package/src/picking/pointerMove.js +5 -0
- package/src/picking/raycast.js +59 -0
- package/src/picking/setHighlight.js +13 -0
- package/src/picking/shouldSkipOther.js +3 -0
- package/src/picking/showFeature.js +34 -0
- package/src/raster/addRasterTile.js +114 -0
- package/src/raster/comparePendingTiles.js +5 -0
- package/src/raster/createGeometry.js +22 -0
- package/src/raster/createRasterMesh.js +47 -0
- package/src/raster/finishAttachment.js +11 -0
- package/src/raster/finishRasterTile.js +47 -0
- package/src/raster/getRasterEvents.js +6 -0
- package/src/raster/getRasterTileSize.js +5 -0
- package/src/raster/initRaster.js +38 -0
- package/src/raster/isLoading.js +5 -0
- package/src/raster/loadRasterTile.js +10 -0
- package/src/raster/onPMTileAdd.js +10 -0
- package/src/raster/onPMTileRemove.js +8 -0
- package/src/raster/pruneRasterTiles.js +37 -0
- package/src/raster/pumpRasterTiles.js +22 -0
- package/src/raster/readyRaster.js +13 -0
- package/src/raster/registerTerrainTile.js +12 -0
- package/src/raster/releaseRasterTile.js +18 -0
- package/src/raster/releaseRasterTiles.js +15 -0
- package/src/raster/removeRasterTile.js +13 -0
- package/src/raster/reportError.js +6 -0
- package/src/raster/setPMTileOpacity.js +7 -0
- package/src/raster/setPMTileZIndex.js +7 -0
- package/src/raster/setRasterOpacity.js +11 -0
- package/src/raster/setRasterTerrain.js +21 -0
- package/src/raster/setRasterZIndex.js +11 -0
- package/src/raster/updateAttachedTiles.js +10 -0
- package/src/raster/updateRasterTiles.js +59 -0
- package/src/rendering/collectFrameMeshes.js +31 -0
- package/src/rendering/collectMeshes.js +36 -0
- package/src/rendering/compareMeshes.js +10 -0
- package/src/rendering/compareRoofTiles.js +4 -0
- package/src/rendering/composeRoofAtlas.js +52 -0
- package/src/rendering/createMesh.js +33 -0
- package/src/rendering/createProgram.js +92 -0
- package/src/rendering/destroyAfterSubmission.js +8 -0
- package/src/rendering/destroyTexture.js +6 -0
- package/src/rendering/disposeMesh.js +14 -0
- package/src/rendering/drawGeometry.js +129 -0
- package/src/rendering/drawSceneMeshes.js +51 -0
- package/src/rendering/ensureRoofBlit.js +40 -0
- package/src/rendering/prepareFrameMeshes.js +42 -0
- package/src/rendering/prepareFrameUniforms.js +49 -0
- package/src/rendering/rebuildRoofAtlas.js +67 -0
- package/src/rendering/render.js +57 -0
- package/src/rendering/reportCompilation.js +17 -0
- package/src/rendering/resizeRenderer.js +19 -0
- package/src/rendering/sortMeshes.js +6 -0
- package/src/rendering/synchronizeZoomView.js +34 -0
- package/src/rendering/textureBinding.js +7 -0
- package/src/rendering/updateMapCamera.js +32 -0
- package/src/rendering/updateRoofRaster.js +32 -0
- package/src/scene/attach.js +161 -0
- package/src/scene/attachLayer.js +10 -0
- package/src/scene/cancelUpdate.js +10 -0
- package/src/scene/emptyEvents.js +3 -0
- package/src/scene/emptyNode.js +11 -0
- package/src/scene/endZoom.js +16 -0
- package/src/scene/failAttachment.js +9 -0
- package/src/scene/get3DEvents.js +13 -0
- package/src/scene/init3D.js +30 -0
- package/src/scene/initializeLayer.js +16 -0
- package/src/scene/initializerFor.js +14 -0
- package/src/scene/layerInitialize.js +38 -0
- package/src/scene/layerLayerAdd.js +21 -0
- package/src/scene/onAdd3DLayer.js +35 -0
- package/src/scene/onMapChange.js +16 -0
- package/src/scene/onRemove3DLayer.js +69 -0
- package/src/scene/onZoomAnim.js +16 -0
- package/src/scene/placeEntry.js +11 -0
- package/src/scene/placeUnderEntry.js +8 -0
- package/src/scene/ready3D.js +25 -0
- package/src/scene/releaseRenderer.js +14 -0
- package/src/scene/removeEntry.js +6 -0
- package/src/scene/renderPendingMapChange.js +11 -0
- package/src/scene/renderPendingUpdates.js +19 -0
- package/src/scene/renderPendingZoomAnimation.js +7 -0
- package/src/scene/rendererDeviceError.js +10 -0
- package/src/scene/rendererDeviceLost.js +11 -0
- package/src/scene/replaceEntry.js +7 -0
- package/src/scene/reportError.js +3 -0
- package/src/scene/requestAdapter.js +12 -0
- package/src/scene/requestDevice.js +9 -0
- package/src/scene/resolveNextInitialization.js +12 -0
- package/src/scene/restoreObject.js +71 -0
- package/src/scene/runPlacements.js +7 -0
- package/src/scene/setParent.js +7 -0
- package/src/scene/showWebGPUWarning.js +16 -0
- package/src/scene/startZoom.js +5 -0
- package/src/scene/traverse.js +7 -0
- package/src/scene/underEntry.js +17 -0
- package/src/scene/update.js +19 -0
- package/src/scene/updateCamera.js +34 -0
- package/src/scene/updateWorldMatrix.js +48 -0
- package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
- package/src/shadows/bindSunlight.js +12 -0
- package/src/shadows/drawShadowMeshes.js +48 -0
- package/src/shadows/ensureShadowPipeline.js +53 -0
- package/src/shadows/renderSunlight.js +46 -0
- package/src/shadows/resizeSunlight.js +15 -0
- package/src/shadows/shadowBounds.js +32 -0
- package/src/shadows/shadowCacheMatches.js +23 -0
- package/src/shadows/shadowMatrix.js +39 -0
- package/src/sources/addGeneratedTriangle.js +6 -0
- package/src/sources/addTriangle.js +17 -0
- package/src/sources/attachAreaMesh.js +58 -0
- package/src/sources/buildArea.js +42 -0
- package/src/sources/buildAreaFeature.js +41 -0
- package/src/sources/buildAreaPoint.js +25 -0
- package/src/sources/buildAreaPolygon.js +29 -0
- package/src/sources/compareAreaDistance.js +4 -0
- package/src/sources/generateTreeGeometry.js +11 -0
- package/src/sources/groundOffset.js +3 -0
- package/src/sources/initializeGeoJSON.js +8 -0
- package/src/sources/instanceAreaGeometry.js +29 -0
- package/src/sources/projectRing.js +20 -0
- package/src/sources/projectedTree.js +13 -0
- package/src/sources/pump.js +54 -0
- package/src/sources/releaseArea.js +22 -0
- package/src/sources/setGeoJSONData.js +12 -0
- package/src/sources/setGeoJSONLayerData.js +5 -0
- package/src/sources/sourceAreaContext.js +9 -0
- package/src/sources/updateArea.js +45 -0
- package/src/sources/updateStatus.js +12 -0
- package/src/sunlight/addTimeLayer.js +3 -0
- package/src/sunlight/addTo.js +10 -0
- package/src/sunlight/atmosphere.js +28 -0
- package/src/sunlight/horizontalPosition.js +16 -0
- package/src/sunlight/initSunlight.js +14 -0
- package/src/sunlight/initialize.js +11 -0
- package/src/sunlight/mix.js +6 -0
- package/src/sunlight/moonPosition.js +17 -0
- package/src/sunlight/onAdd.js +5 -0
- package/src/sunlight/onAddSun.js +66 -0
- package/src/sunlight/projectCelestialBody.js +13 -0
- package/src/sunlight/remove.js +7 -0
- package/src/sunlight/removeSun.js +15 -0
- package/src/sunlight/removeTimeLayer.js +3 -0
- package/src/sunlight/render.js +7 -0
- package/src/sunlight/rgb.js +6 -0
- package/src/sunlight/solarPosition.js +17 -0
- package/src/sunlight/styleTimeControl.js +7 -0
- package/src/sunlight/tickSun.js +5 -0
- package/src/sunlight/updateSky.js +20 -0
- package/src/sunlight/updateSun.js +34 -0
- package/src/sunlight/useLiveTime.js +6 -0
- package/src/sunlight/useSelectedTime.js +20 -0
- package/src/terrain/clearLayerTerrain.js +5 -0
- package/src/terrain/getElevation.js +10 -0
- package/src/terrain/initTerrain.js +20 -0
- package/src/terrain/loadReadyTerrain.js +5 -0
- package/src/terrain/loadTerrain.js +63 -0
- package/src/terrain/loadTerrainTiles.js +13 -0
- package/src/terrain/onTerrainAdd.js +21 -0
- package/src/terrain/onTerrainChange.js +14 -0
- package/src/terrain/onTerrainRemove.js +41 -0
- package/src/terrain/readBridges.js +4 -0
- package/src/terrain/sample.js +7 -0
- package/src/terrain/setLayerTerrain.js +5 -0
- package/src/terrain/setTerrainHeight.js +10 -0
- package/src/terrain/terrainAtlas.js +23 -0
- package/src/terrain/terrainElevation.js +20 -0
- package/src/terrain/terrainGrid.js +24 -0
- package/src/traffic/addTraffic.js +7 -0
- package/src/traffic/along.js +14 -0
- package/src/traffic/clockMinutes.js +6 -0
- package/src/traffic/compareDepartures.js +5 -0
- package/src/traffic/createTrafficMesh.js +7 -0
- package/src/traffic/destroyTrafficGpu.js +5 -0
- package/src/traffic/disposeTrafficObject.js +13 -0
- package/src/traffic/drawTrafficRoute.js +6 -0
- package/src/traffic/failTraffic.js +6 -0
- package/src/traffic/failedTrafficLoad.js +5 -0
- package/src/traffic/fetchTrafficLanes.js +10 -0
- package/src/traffic/groundTraffic.js +15 -0
- package/src/traffic/initTraffic.js +54 -0
- package/src/traffic/loadTraffic.js +15 -0
- package/src/traffic/loadedTrafficLanes.js +16 -0
- package/src/traffic/locateTraffic.js +9 -0
- package/src/traffic/moveTraffic.js +15 -0
- package/src/traffic/placeTraffic.js +21 -0
- package/src/traffic/prepareTraffic.js +25 -0
- package/src/traffic/readyTraffic.js +6 -0
- package/src/traffic/rebaseTraffic.js +58 -0
- package/src/traffic/rebuildTrafficMesh.js +28 -0
- package/src/traffic/removeTraffic.js +17 -0
- package/src/traffic/routeColor.js +6 -0
- package/src/traffic/routeGeometry.js +31 -0
- package/src/traffic/scheduledTrips.js +40 -0
- package/src/traffic/startTraffic.js +8 -0
- package/src/traffic/tickTraffic.js +57 -0
- package/src/traffic/toLanes.js +16 -0
- package/src/traffic/tooltip.js +11 -0
- package/src/traffic/trafficBounds.js +17 -0
- package/src/traffic/trafficNow.js +4 -0
- package/src/traffic/trafficStorage.js +5 -0
- package/src/traffic/tripsAt.js +27 -0
- package/src/traffic/updateTraffic.js +8 -0
- package/src/traffic/updateTrafficTerrain.js +12 -0
- package/src/traffic/vehicleOffsets.js +11 -0
- package/src/triangulation/area.js +9 -0
- package/src/triangulation/clean.js +18 -0
- package/src/triangulation/containsVertex.js +11 -0
- package/src/triangulation/cross.js +3 -0
- package/src/triangulation/crossesBoundary.js +8 -0
- package/src/triangulation/crossesRing.js +9 -0
- package/src/triangulation/equal.js +3 -0
- package/src/triangulation/inside.js +10 -0
- package/src/triangulation/insideHole.js +7 -0
- package/src/triangulation/intersects.js +11 -0
- package/src/triangulation/isClockWise.js +13 -0
- package/src/triangulation/minimumX.js +6 -0
- package/src/triangulation/on.js +4 -0
- package/src/triangulation/sortHoles.js +26 -0
- package/src/triangulation/triangulate.js +86 -0
- package/src/utils/channel.js +4 -0
- package/src/utils/compareDistance.js +3 -0
- package/src/utils/noOperation.js +1 -0
- package/src/utils/parseColor.js +42 -0
- package/src/utils/toSRGB.js +3 -0
- package/src/utils/wrap.js +3 -0
- package/src/vehicles/bicycleModel.js +23 -0
- package/src/vehicles/boatBenches.js +8 -0
- package/src/vehicles/boatModel.js +27 -0
- package/src/vehicles/busModel.js +6 -0
- package/src/vehicles/carModel.js +22 -0
- package/src/vehicles/carriage.js +19 -0
- package/src/vehicles/metroModel.js +9 -0
- package/src/vehicles/mirror.js +8 -0
- package/src/vehicles/pedestrianModel.js +17 -0
- package/src/vehicles/tramModel.js +9 -0
- package/src/walk/blocked.js +6 -0
- package/src/walk/createWalk.js +60 -0
- package/src/walk/initWalk.js +18 -0
- package/src/walk/initialize.js +6 -0
- package/src/walk/local.js +10 -0
- package/src/walk/onAdd.js +4 -0
- package/src/walk/onBlur.js +3 -0
- package/src/walk/onKey.js +12 -0
- package/src/walk/onPointer.js +13 -0
- package/src/walk/onRemove.js +4 -0
- package/src/walk/onTerrain.js +5 -0
- package/src/walk/place.js +18 -0
- package/src/walk/start.js +37 -0
- package/src/walk/step.js +53 -0
- package/src/walk/stop.js +27 -0
- package/src/walk/toggle.js +6 -0
- package/dist/scene/gpu.js +0 -3
- package/dist/scene/gpu.js.map +0 -7
- package/dist/scene/lighting.js +0 -9
- package/dist/scene/lighting.js.map +0 -7
- package/dist/scene/model.js +0 -2
- package/dist/scene/model.js.map +0 -7
- package/dist/scene/picking.js +0 -2
- package/dist/scene/picking.js.map +0 -7
- package/dist/scene/pmtiles.js +0 -2
- package/dist/scene/pmtiles.js.map +0 -7
- package/dist/scene/render.js +0 -15
- package/dist/scene/render.js.map +0 -7
- package/dist/scene/sources.js +0 -2
- package/dist/scene/sources.js.map +0 -7
- package/dist/types/3d.js +0 -2
- package/dist/types/3d.js.map +0 -7
- package/dist/types/geojson.js +0 -2
- package/dist/types/geojson.js.map +0 -7
- package/dist/types/pmtiles.js +0 -2
- package/dist/types/pmtiles.js.map +0 -7
- package/dist/types/sunlight.js +0 -2
- package/dist/types/sunlight.js.map +0 -7
- package/dist/types/terrain.js +0 -24
- package/dist/types/terrain.js.map +0 -7
- package/dist/types/traffic.js +0 -41
- package/dist/types/traffic.js.map +0 -7
- package/dist/types/walk.js +0 -2
- package/dist/types/walk.js.map +0 -7
- package/dist/utils/control.js +0 -2
- package/dist/utils/control.js.map +0 -7
- package/dist/utils/geometry.js +0 -2
- package/dist/utils/geometry.js.map +0 -7
- package/dist/utils/lighting.js +0 -2
- package/dist/utils/lighting.js.map +0 -7
- package/dist/utils/model.js +0 -2
- package/dist/utils/model.js.map +0 -7
- package/dist/utils/picking.js +0 -2
- package/dist/utils/picking.js.map +0 -7
- package/dist/utils/pmtiles.js +0 -2
- package/dist/utils/pmtiles.js.map +0 -7
- package/dist/utils/scene.js +0 -2
- package/dist/utils/scene.js.map +0 -7
- package/dist/utils/shaders.js +0 -203
- package/dist/utils/shaders.js.map +0 -7
- package/dist/utils/sun.js +0 -2
- package/dist/utils/sun.js.map +0 -7
- package/dist/utils/terrain.js +0 -2
- package/dist/utils/terrain.js.map +0 -7
- package/dist/utils/traffic.js +0 -2
- package/dist/utils/traffic.js.map +0 -7
- package/dist/utils/vehicles.js +0 -2
- package/dist/utils/vehicles.js.map +0 -7
- package/dist/utils/walk.js +0 -2
- package/dist/utils/walk.js.map +0 -7
- package/src/scene/gpu.js +0 -438
- package/src/scene/lighting.js +0 -193
- package/src/scene/model.js +0 -204
- package/src/scene/picking.js +0 -150
- package/src/scene/pmtiles.js +0 -94
- package/src/scene/render.js +0 -467
- package/src/scene/sources.js +0 -265
- package/src/types/3d.js +0 -337
- package/src/types/geojson.js +0 -42
- package/src/types/pmtiles.js +0 -143
- package/src/types/sunlight.js +0 -142
- package/src/types/terrain.js +0 -331
- package/src/types/traffic.js +0 -356
- package/src/types/walk.js +0 -219
- package/src/utils/control.js +0 -18
- package/src/utils/geometry.js +0 -256
- package/src/utils/lighting.js +0 -51
- package/src/utils/model.js +0 -178
- package/src/utils/picking.js +0 -119
- package/src/utils/pmtiles.js +0 -79
- package/src/utils/scene.js +0 -102
- package/src/utils/sun.js +0 -71
- package/src/utils/terrain.js +0 -78
- package/src/utils/traffic.js +0 -90
- package/src/utils/vehicles.js +0 -69
- package/src/utils/walk.js +0 -72
package/src/scene/render.js
DELETED
|
@@ -1,467 +0,0 @@
|
|
|
1
|
-
import { computeBounds } from '../utils/geometry.js';
|
|
2
|
-
import { traverse, updateWorldMatrix, updateCamera } from '../utils/scene.js';
|
|
3
|
-
|
|
4
|
-
/** Scene graph, shared camera and frame rendering. */
|
|
5
|
-
/** Content changes: render once on the next animation frame. */
|
|
6
|
-
export function update(backend) {
|
|
7
|
-
const shared = backend._shared;
|
|
8
|
-
if (!shared) return backend;
|
|
9
|
-
if (shared !== backend) {
|
|
10
|
-
shared.update();
|
|
11
|
-
return backend;
|
|
12
|
-
}
|
|
13
|
-
backend._frame ||= requestAnimationFrame(() => {
|
|
14
|
-
backend._frame = null;
|
|
15
|
-
if (backend._shared === backend && backend.renderer) backend._render();
|
|
16
|
-
});
|
|
17
|
-
return backend;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Map movement: render within the frame of Leaflet's CSS transforms, coalescing same-tick events. */
|
|
21
|
-
export function onMapChange(backend) {
|
|
22
|
-
if (backend._queued) return;
|
|
23
|
-
backend._queued = true;
|
|
24
|
-
queueMicrotask(() => {
|
|
25
|
-
backend._queued = false;
|
|
26
|
-
if (backend._shared !== backend || !backend.renderer) return;
|
|
27
|
-
if (backend._map._animatingZoom) backend.update();
|
|
28
|
-
else backend._render();
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Find a raster tile's active CSS level to reproduce Leaflet's animated scale/rounding. */
|
|
33
|
-
export function getTileLevel(backend) {
|
|
34
|
-
let level;
|
|
35
|
-
backend._map.eachLayer(layer => {
|
|
36
|
-
if (!level && layer instanceof L.TileLayer && layer._levels) {
|
|
37
|
-
level = layer._levels[layer._tileZoom];
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return level;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Preserve the outgoing tile level before Leaflet changes its logical zoom. */
|
|
44
|
-
export function startZoom(backend) {
|
|
45
|
-
backend._zoomLevel = backend._getTileLevel();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** Stop using the outgoing level after zoomend; the next redraw uses current tiles. */
|
|
49
|
-
export function endZoom(backend) {
|
|
50
|
-
for (const animation of backend._zoomTransitions?.keys() || []) animation.finish();
|
|
51
|
-
backend._zoomTransitions = null;
|
|
52
|
-
backend._zoomLevel = null;
|
|
53
|
-
backend.update();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Rendering owner: CSS pixels -> scene metres -> perspective camera.
|
|
58
|
-
* Lights and transparent sort centers are converted into the current camera space.
|
|
59
|
-
* Without raster tiles, logical map projection supplies the same static alignment.
|
|
60
|
-
*/
|
|
61
|
-
export function render(backend) {
|
|
62
|
-
cancelAnimationFrame(backend._frame);
|
|
63
|
-
backend._frame = null;
|
|
64
|
-
if (backend._shared !== backend || !backend.renderer) return;
|
|
65
|
-
const map = backend._map;
|
|
66
|
-
const size = map.getSize();
|
|
67
|
-
if (!size.x || !size.y) return;
|
|
68
|
-
if (map._animatingZoom) {
|
|
69
|
-
backend._zoomTransitions ||= new Map();
|
|
70
|
-
const now = performance.now();
|
|
71
|
-
for (const animation of map.getContainer().getAnimations({ subtree: true })) {
|
|
72
|
-
if (!(animation instanceof CSSTransition) || animation.transitionProperty !== 'transform' ||
|
|
73
|
-
!animation.effect.target.classList.contains('leaflet-zoom-animated') ||
|
|
74
|
-
backend._zoomTransitions.has(animation)
|
|
75
|
-
) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
const time = animation.currentTime || 0;
|
|
79
|
-
animation.pause();
|
|
80
|
-
backend._zoomTransitions.set(animation, { start: now, time });
|
|
81
|
-
}
|
|
82
|
-
// Freeze CSS between rendered frames: the compositor must not outrun the canvas.
|
|
83
|
-
for (const [animation, { start, time }] of backend._zoomTransitions) {
|
|
84
|
-
animation.currentTime = Math.min(animation.effect.getComputedTiming().endTime, time + now - start);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!backend._size || !backend._size.equals(size)) {
|
|
88
|
-
backend.renderer.width = size.x;
|
|
89
|
-
backend.renderer.height = size.y;
|
|
90
|
-
backend.renderer.canvas.width = Math.round(size.x * backend.renderer.dpr);
|
|
91
|
-
backend.renderer.canvas.height = Math.round(size.y * backend.renderer.dpr);
|
|
92
|
-
backend.renderer.canvas.style.width = `${size.x}px`;
|
|
93
|
-
backend.renderer.canvas.style.height = `${size.y}px`;
|
|
94
|
-
if (backend.renderer.depthTexture) backend._destroyTexture(backend.renderer.depthTexture);
|
|
95
|
-
backend.renderer.depthTexture = backend.renderer.device.createTexture({
|
|
96
|
-
size: [backend.renderer.canvas.width, backend.renderer.canvas.height],
|
|
97
|
-
format: 'depth24plus',
|
|
98
|
-
usage: GPUTextureUsage.RENDER_ATTACHMENT,
|
|
99
|
-
});
|
|
100
|
-
backend._size = size;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Match the map's CSS camera: a perspective distance of 1.5 viewport heights.
|
|
104
|
-
let pixelsPerMeter = map.options.crs.scale(map.getZoom()) / (40075016.68557849 * Math.cos(backend._sceneOrigin.lat * Math.PI / 180));
|
|
105
|
-
let origin = map.project(backend._sceneOrigin).subtract(map.getPixelOrigin());
|
|
106
|
-
const level = backend._zoomLevel?.el.isConnected ? backend._zoomLevel : backend._getTileLevel();
|
|
107
|
-
if (level && map._animatingZoom) {
|
|
108
|
-
backend._zoomLevel = level;
|
|
109
|
-
}
|
|
110
|
-
// Leaflet's logical zoom jumps before its tile CSS transition finishes.
|
|
111
|
-
// Use the rendered tile transform, including its rounding, on every animation frame.
|
|
112
|
-
if (level) {
|
|
113
|
-
const transform = new DOMMatrix(map._animatingZoom ? getComputedStyle(level.el).transform : level.el.style.transform);
|
|
114
|
-
const point = map.project(backend._sceneOrigin, level.zoom).subtract(level.origin);
|
|
115
|
-
origin = new L.Point(point.x * transform.a + transform.e, point.y * transform.d + transform.f);
|
|
116
|
-
pixelsPerMeter *= map.getZoomScale(level.zoom, map.getZoom()) * transform.a;
|
|
117
|
-
}
|
|
118
|
-
const distance = size.y * 1.5 / pixelsPerMeter;
|
|
119
|
-
const center = map.containerPointToLayerPoint(size.divideBy(2));
|
|
120
|
-
const target = [
|
|
121
|
-
(center.x - origin.x) / pixelsPerMeter,
|
|
122
|
-
map._terrain3D?._getElevation(map.getCenter()) ?? 0,
|
|
123
|
-
(center.y - origin.y) / pixelsPerMeter
|
|
124
|
-
];
|
|
125
|
-
const pitch = map.getPitch() * Math.PI / 180;
|
|
126
|
-
const bearing = map.getBearing() * Math.PI / 180;
|
|
127
|
-
const camera = backend.camera;
|
|
128
|
-
camera.fov = 2 * Math.atan(1 / 3) * 180 / Math.PI;
|
|
129
|
-
camera.aspect = size.x / size.y;
|
|
130
|
-
camera.near = Math.max(0.1, distance / 10000);
|
|
131
|
-
camera.far = Math.max(10000, distance * 10);
|
|
132
|
-
camera.position[0] = target[0] + Math.sin(bearing) * Math.sin(pitch) * distance;
|
|
133
|
-
camera.position[1] = target[1] + Math.cos(pitch) * distance;
|
|
134
|
-
camera.position[2] = target[2] + Math.cos(bearing) * Math.sin(pitch) * distance;
|
|
135
|
-
camera.up[0] = -Math.sin(bearing) * Math.cos(pitch);
|
|
136
|
-
camera.up[1] = Math.sin(pitch);
|
|
137
|
-
camera.up[2] = -Math.cos(bearing) * Math.cos(pitch);
|
|
138
|
-
camera.target[0] = target[0]; camera.target[1] = target[1]; camera.target[2] = target[2];
|
|
139
|
-
// Refresh the camera view, projection and combined projection-view matrices.
|
|
140
|
-
updateCamera(camera);
|
|
141
|
-
const sunlight = map._sunlight;
|
|
142
|
-
const lightPoint = new DOMPoint(...(sunlight?.direction || [-300, 500, 300]), 0).matrixTransform(new DOMMatrix(camera.viewMatrix));
|
|
143
|
-
const lightLength = Math.hypot(lightPoint.x, lightPoint.y, lightPoint.z) || 1;
|
|
144
|
-
const light = [lightPoint.x / lightLength, lightPoint.y / lightLength, lightPoint.z / lightLength];
|
|
145
|
-
const skyPoint = new DOMPoint(0, 1, 0, 0).matrixTransform(new DOMMatrix(camera.viewMatrix));
|
|
146
|
-
const skyLength = Math.hypot(skyPoint.x, skyPoint.y, skyPoint.z) || 1;
|
|
147
|
-
const sky = [skyPoint.x / skyLength, skyPoint.y / skyLength, skyPoint.z / skyLength];
|
|
148
|
-
const projection = camera.projectionViewMatrix;
|
|
149
|
-
const frustum = [
|
|
150
|
-
[projection[3] + projection[0], projection[7] + projection[4], projection[11] + projection[8], projection[15] + projection[12]],
|
|
151
|
-
[projection[3] - projection[0], projection[7] - projection[4], projection[11] - projection[8], projection[15] - projection[12]],
|
|
152
|
-
[projection[3] + projection[1], projection[7] + projection[5], projection[11] + projection[9], projection[15] + projection[13]],
|
|
153
|
-
[projection[3] - projection[1], projection[7] - projection[5], projection[11] - projection[9], projection[15] - projection[13]],
|
|
154
|
-
[projection[2], projection[6], projection[10], projection[14]],
|
|
155
|
-
[projection[3] - projection[2], projection[7] - projection[6], projection[11] - projection[10], projection[15] - projection[14]],
|
|
156
|
-
];
|
|
157
|
-
const frustumLengths = [
|
|
158
|
-
Math.hypot(frustum[0][0], frustum[0][1], frustum[0][2]),
|
|
159
|
-
Math.hypot(frustum[1][0], frustum[1][1], frustum[1][2]),
|
|
160
|
-
Math.hypot(frustum[2][0], frustum[2][1], frustum[2][2]),
|
|
161
|
-
Math.hypot(frustum[3][0], frustum[3][1], frustum[3][2]),
|
|
162
|
-
Math.hypot(frustum[4][0], frustum[4][1], frustum[4][2]),
|
|
163
|
-
Math.hypot(frustum[5][0], frustum[5][1], frustum[5][2]),
|
|
164
|
-
];
|
|
165
|
-
updateWorldMatrix(backend.scene);
|
|
166
|
-
traverse(backend.scene, mesh => {
|
|
167
|
-
if (!mesh.visible) return true;
|
|
168
|
-
if (mesh.geometry) {
|
|
169
|
-
if (!mesh.geometry.bounds) computeBounds(mesh.geometry);
|
|
170
|
-
const bounds = mesh.geometry.bounds;
|
|
171
|
-
const world = mesh.worldMatrix;
|
|
172
|
-
const center = bounds.center;
|
|
173
|
-
const x = world[0] * center[0] + world[4] * center[1] + world[8] * center[2] + world[12];
|
|
174
|
-
const y = world[1] * center[0] + world[5] * center[1] + world[9] * center[2] + world[13];
|
|
175
|
-
const z = world[2] * center[0] + world[6] * center[1] + world[10] * center[2] + world[14];
|
|
176
|
-
const radius = bounds.radius * Math.max(
|
|
177
|
-
Math.hypot(world[0], world[1], world[2]),
|
|
178
|
-
Math.hypot(world[4], world[5], world[6]),
|
|
179
|
-
Math.hypot(world[8], world[9], world[10])
|
|
180
|
-
);
|
|
181
|
-
mesh._visibleInFrame =
|
|
182
|
-
frustum[0][0] * x + frustum[0][1] * y + frustum[0][2] * z + frustum[0][3] >= -radius * frustumLengths[0] &&
|
|
183
|
-
frustum[1][0] * x + frustum[1][1] * y + frustum[1][2] * z + frustum[1][3] >= -radius * frustumLengths[1] &&
|
|
184
|
-
frustum[2][0] * x + frustum[2][1] * y + frustum[2][2] * z + frustum[2][3] >= -radius * frustumLengths[2] &&
|
|
185
|
-
frustum[3][0] * x + frustum[3][1] * y + frustum[3][2] * z + frustum[3][3] >= -radius * frustumLengths[3] &&
|
|
186
|
-
frustum[4][0] * x + frustum[4][1] * y + frustum[4][2] * z + frustum[4][3] >= -radius * frustumLengths[4] &&
|
|
187
|
-
frustum[5][0] * x + frustum[5][1] * y + frustum[5][2] * z + frustum[5][3] >= -radius * frustumLengths[5];
|
|
188
|
-
if (!mesh._visibleInFrame) return;
|
|
189
|
-
}
|
|
190
|
-
if (mesh.program?.transparent) {
|
|
191
|
-
if (!mesh.geometry.bounds) computeBounds(mesh.geometry);
|
|
192
|
-
const center = mesh.geometry.bounds.center, world = mesh.worldMatrix;
|
|
193
|
-
const x = world[0] * center[0] + world[4] * center[1] + world[8] * center[2] + world[12];
|
|
194
|
-
const y = world[1] * center[0] + world[5] * center[1] + world[9] * center[2] + world[13];
|
|
195
|
-
const z = world[2] * center[0] + world[6] * center[1] + world[10] * center[2] + world[14];
|
|
196
|
-
const projection = camera.projectionViewMatrix;
|
|
197
|
-
const clipZ = projection[2] * x + projection[6] * y + projection[10] * z + projection[14];
|
|
198
|
-
const clipW = projection[3] * x + projection[7] * y + projection[11] * z + projection[15];
|
|
199
|
-
mesh._sortDepth = clipZ / clipW;
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
const renderer = backend.renderer;
|
|
203
|
-
if ([...backend._layers].some(layer => layer.options.roofTexture)) {
|
|
204
|
-
const rasters = Object.values(map._layers).filter(layer =>
|
|
205
|
-
layer instanceof L.Layer.types.pmtiles && layer._tiles && layer.options.opacity > 0);
|
|
206
|
-
const tiles = rasters.flatMap(layer => Object.values(layer._tiles)
|
|
207
|
-
.filter(tile => tile.el.done && !tile.el.request.signal.aborted && tile.el.isConnected)
|
|
208
|
-
.map(tile => ({ ...tile, layer })));
|
|
209
|
-
const signature = tiles.map(({ el, coords, layer }) =>
|
|
210
|
-
`${L.Util.stamp(el)}:${coords.z}:${coords.x}:${coords.y}:${layer.options.opacity}:${layer.options.zIndex}`).join('|');
|
|
211
|
-
const selection = rasters.map(layer =>
|
|
212
|
-
`${L.Util.stamp(layer)}:${layer.options.opacity}:${layer.options.zIndex}`).join('|');
|
|
213
|
-
// Retain the geographically aligned atlas until a tile batch finishes loading.
|
|
214
|
-
if (!backend._roofRaster || backend._roofRaster.selection !== selection ||
|
|
215
|
-
(!rasters.some(layer => layer.isLoading()) && backend._roofRaster.signature !== signature)) {
|
|
216
|
-
const zoom = tiles.length ? Math.max(...tiles.map(tile => tile.coords.z)) : map.getZoom();
|
|
217
|
-
const bounds = new L.Bounds();
|
|
218
|
-
for (const { coords, layer } of tiles) {
|
|
219
|
-
const size = layer.getTileSize().multiplyBy(map.getZoomScale(zoom, coords.z));
|
|
220
|
-
bounds.extend(new L.Point(coords.x, coords.y).scaleBy(size));
|
|
221
|
-
bounds.extend(new L.Point(coords.x + 1, coords.y + 1).scaleBy(size));
|
|
222
|
-
}
|
|
223
|
-
const min = bounds.min || map.project(backend._sceneOrigin, zoom);
|
|
224
|
-
const size = bounds.isValid() ? bounds.getSize() : new L.Point(1, 1);
|
|
225
|
-
// ponytail: cap at 4096 px; virtual textures if wide views need native detail.
|
|
226
|
-
const limit = 4096;
|
|
227
|
-
const scale = Math.min(1, limit / Math.max(size.x, size.y));
|
|
228
|
-
const width = Math.max(1, Math.ceil(size.x * scale));
|
|
229
|
-
const height = Math.max(1, Math.ceil(size.y * scale));
|
|
230
|
-
const origin = map.project(backend._sceneOrigin, zoom);
|
|
231
|
-
const pixels = map.options.crs.scale(zoom) / (40075016.68557849 * Math.cos(backend._sceneOrigin.lat * Math.PI / 180));
|
|
232
|
-
const matrix = new DOMMatrix();
|
|
233
|
-
matrix.m11 = pixels / size.x; matrix.m33 = pixels / size.y;
|
|
234
|
-
matrix.m41 = (origin.x - min.x) / size.x; matrix.m43 = (origin.y - min.y) / size.y;
|
|
235
|
-
const texture = backend._roofRaster?.texture;
|
|
236
|
-
if (texture && (texture.width !== width || texture.height !== height)) {
|
|
237
|
-
backend._destroyTexture(texture.texture);
|
|
238
|
-
texture.texture = renderer.device.createTexture({
|
|
239
|
-
size: [width, height],
|
|
240
|
-
format: 'rgba8unorm',
|
|
241
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
242
|
-
});
|
|
243
|
-
texture.width = width;
|
|
244
|
-
texture.height = height;
|
|
245
|
-
}
|
|
246
|
-
backend._roofRaster = {
|
|
247
|
-
signature, selection, matrix: Array.from(matrix.toFloat64Array()),
|
|
248
|
-
texture: texture || {
|
|
249
|
-
device: renderer.device,
|
|
250
|
-
texture: renderer.device.createTexture({
|
|
251
|
-
size: [width, height],
|
|
252
|
-
format: 'rgba8unorm',
|
|
253
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
254
|
-
}),
|
|
255
|
-
sampler: renderer.device.createSampler({
|
|
256
|
-
addressModeU: 'clamp-to-edge', addressModeV: 'clamp-to-edge',
|
|
257
|
-
}),
|
|
258
|
-
samplerOptions: { addressModeU: 'clamp-to-edge', addressModeV: 'clamp-to-edge' },
|
|
259
|
-
image: null, width, height,
|
|
260
|
-
format: 'rgba8unorm', srgb: false, flipY: false, uploaded: null,
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
// Compose the atlas on the GPU: re-uploading a large canvas stalls Firefox for hundreds of ms.
|
|
264
|
-
const device = renderer.device;
|
|
265
|
-
if (!renderer.roofBlit) {
|
|
266
|
-
const module = device.createShaderModule({ code: `
|
|
267
|
-
@group(0) @binding(0) var source: texture_2d<f32>;
|
|
268
|
-
@group(0) @binding(1) var sourceSampler: sampler;
|
|
269
|
-
@group(0) @binding(2) var<uniform> opacity: f32;
|
|
270
|
-
struct Varyings { @builtin(position) position: vec4f, @location(0) uv: vec2f };
|
|
271
|
-
@vertex fn vertexMain(@builtin(vertex_index) index: u32) -> Varyings {
|
|
272
|
-
let uv = vec2f(f32(index & 1u), f32(index >> 1u));
|
|
273
|
-
return Varyings(vec4f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, 0.0, 1.0), uv);
|
|
274
|
-
}
|
|
275
|
-
@fragment fn fragmentMain(input: Varyings) -> @location(0) vec4f {
|
|
276
|
-
let color = textureSample(source, sourceSampler, input.uv);
|
|
277
|
-
return vec4f(color.rgb, color.a * opacity);
|
|
278
|
-
}
|
|
279
|
-
` });
|
|
280
|
-
renderer.roofBlit = {
|
|
281
|
-
pipeline: device.createRenderPipeline({
|
|
282
|
-
layout: 'auto',
|
|
283
|
-
vertex: { module, entryPoint: 'vertexMain' },
|
|
284
|
-
fragment: {
|
|
285
|
-
module,
|
|
286
|
-
entryPoint: 'fragmentMain',
|
|
287
|
-
targets: [{
|
|
288
|
-
format: 'rgba8unorm',
|
|
289
|
-
blend: {
|
|
290
|
-
color: { srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha', operation: 'add' },
|
|
291
|
-
alpha: { srcFactor: 'one', dstFactor: 'one-minus-src-alpha', operation: 'add' },
|
|
292
|
-
},
|
|
293
|
-
}],
|
|
294
|
-
},
|
|
295
|
-
primitive: { topology: 'triangle-strip' },
|
|
296
|
-
}),
|
|
297
|
-
sampler: device.createSampler({ magFilter: 'linear', minFilter: 'linear' }),
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
// Raster tiles keep their GPU copy; terrain meshes already own one for the same image.
|
|
301
|
-
const roofTiles = backend._roofTiles ||= new Map();
|
|
302
|
-
for (const [el, source] of roofTiles) {
|
|
303
|
-
if (!tiles.some(tile => tile.el === el) || map._terrain3D?._rasterTiles.has(el)) {
|
|
304
|
-
source.texture.destroy();
|
|
305
|
-
roofTiles.delete(el);
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const opacities = new Float32Array(Math.max(1, tiles.length) * 64);
|
|
309
|
-
const opacityBuffer = device.createBuffer({
|
|
310
|
-
size: opacities.byteLength,
|
|
311
|
-
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
|
312
|
-
});
|
|
313
|
-
const encoder = device.createCommandEncoder();
|
|
314
|
-
const atlasPass = encoder.beginRenderPass({
|
|
315
|
-
colorAttachments: [{
|
|
316
|
-
view: backend._roofRaster.texture.texture.createView(),
|
|
317
|
-
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
318
|
-
loadOp: 'clear',
|
|
319
|
-
storeOp: 'store',
|
|
320
|
-
}],
|
|
321
|
-
});
|
|
322
|
-
atlasPass.setPipeline(renderer.roofBlit.pipeline);
|
|
323
|
-
tiles.sort((a, b) => (a.layer.options.zIndex || 0) - (b.layer.options.zIndex || 0) || a.coords.z - b.coords.z);
|
|
324
|
-
for (const [i, { coords, el, layer }] of tiles.entries()) {
|
|
325
|
-
let source = map._terrain3D?._rasterTiles.get(el)?.texture || roofTiles.get(el);
|
|
326
|
-
if (!source) {
|
|
327
|
-
source = {
|
|
328
|
-
texture: device.createTexture({
|
|
329
|
-
size: [el.naturalWidth, el.naturalHeight],
|
|
330
|
-
format: 'rgba8unorm',
|
|
331
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
332
|
-
}),
|
|
333
|
-
image: el, uploaded: null,
|
|
334
|
-
};
|
|
335
|
-
roofTiles.set(el, source);
|
|
336
|
-
}
|
|
337
|
-
if (source.uploaded !== source.image) {
|
|
338
|
-
device.queue.copyExternalImageToTexture({ source: el }, { texture: source.texture },
|
|
339
|
-
[source.texture.width, source.texture.height]);
|
|
340
|
-
source.uploaded = source.image;
|
|
341
|
-
}
|
|
342
|
-
opacities[i * 64] = layer.options.opacity;
|
|
343
|
-
const tileSize = layer.getTileSize().multiplyBy(map.getZoomScale(zoom, coords.z));
|
|
344
|
-
const offset = new L.Point(coords.x, coords.y).scaleBy(tileSize).subtract(min);
|
|
345
|
-
const x = offset.x * width / size.x, y = offset.y * height / size.y;
|
|
346
|
-
atlasPass.setViewport(x, y, Math.min(tileSize.x * width / size.x, width - x),
|
|
347
|
-
Math.min(tileSize.y * height / size.y, height - y), 0, 1);
|
|
348
|
-
atlasPass.setBindGroup(0, device.createBindGroup({
|
|
349
|
-
layout: renderer.roofBlit.pipeline.getBindGroupLayout(0),
|
|
350
|
-
entries: [
|
|
351
|
-
{ binding: 0, resource: source.texture.createView() },
|
|
352
|
-
{ binding: 1, resource: renderer.roofBlit.sampler },
|
|
353
|
-
{ binding: 2, resource: { buffer: opacityBuffer, offset: i * 256, size: 4 } },
|
|
354
|
-
],
|
|
355
|
-
}));
|
|
356
|
-
atlasPass.draw(4);
|
|
357
|
-
}
|
|
358
|
-
atlasPass.end();
|
|
359
|
-
device.queue.writeBuffer(opacityBuffer, 0, opacities);
|
|
360
|
-
device.queue.submit([encoder.finish()]);
|
|
361
|
-
opacityBuffer.destroy();
|
|
362
|
-
}
|
|
363
|
-
} else if (backend._roofRaster) {
|
|
364
|
-
backend._destroyTexture(backend._roofRaster.texture.texture);
|
|
365
|
-
backend._roofRaster = null;
|
|
366
|
-
for (const source of backend._roofTiles?.values() || []) source.texture.destroy();
|
|
367
|
-
backend._roofTiles = null;
|
|
368
|
-
}
|
|
369
|
-
// Visible meshes: opaque first, transparent surfaces back-to-front.
|
|
370
|
-
const meshes = [];
|
|
371
|
-
traverse(backend.scene, mesh => { if (!mesh.visible) return true; if (mesh.geometry && mesh._visibleInFrame) meshes.push(mesh); });
|
|
372
|
-
meshes.sort((a, b) => Number(a.program.transparent) - Number(b.program.transparent) ||
|
|
373
|
-
(a.program.transparent
|
|
374
|
-
? (a.renderOrder || 0) - (b.renderOrder || 0) ||
|
|
375
|
-
b._sortDepth - a._sortDepth || a.id - b.id
|
|
376
|
-
: a.id - b.id)
|
|
377
|
-
);
|
|
378
|
-
const encoder = renderer.device.createCommandEncoder();
|
|
379
|
-
const pendingRasterTiles = [];
|
|
380
|
-
// One uniform upload per frame: per-mesh writeBuffer calls dominate Firefox's GPU process.
|
|
381
|
-
// Slot 0 holds the camera; 256-byte mesh slots follow (double-sided meshes use two).
|
|
382
|
-
const shadowMeshes = [];
|
|
383
|
-
if (sunlight?.altitude >= 3) {
|
|
384
|
-
for (const layer of backend._layers) {
|
|
385
|
-
if (layer instanceof L.Layer.types.terrain) continue;
|
|
386
|
-
traverse(layer.root, mesh => {
|
|
387
|
-
if (!mesh.visible) return true;
|
|
388
|
-
if (mesh.geometry && !mesh.tile && !mesh.program.nightLight && mesh.program.depthTest !== false) shadowMeshes.push(mesh);
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
if (!renderer.uniformBuffer || renderer.uniformBuffer.size < (meshes.length * 2 + shadowMeshes.length + 1) * 256) {
|
|
393
|
-
if (renderer.uniformBuffer) backend._destroyTexture(renderer.uniformBuffer);
|
|
394
|
-
renderer.uniformBuffer = renderer.device.createBuffer({
|
|
395
|
-
size: Math.max(64, meshes.length * 4 + shadowMeshes.length * 2) * 256,
|
|
396
|
-
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
|
397
|
-
});
|
|
398
|
-
renderer.uniformData = new Float32Array(renderer.uniformBuffer.size / 4);
|
|
399
|
-
}
|
|
400
|
-
const frameData = renderer.uniformData;
|
|
401
|
-
frameData.set(camera.viewMatrix, 0);
|
|
402
|
-
frameData.set(camera.projectionMatrix, 16);
|
|
403
|
-
frameData.set(backend._roofRaster?.matrix || [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], 32);
|
|
404
|
-
frameData.set(light, 48);
|
|
405
|
-
frameData[51] = sunlight && sunlight.altitude <= 0 ? 0 : 1;
|
|
406
|
-
frameData.set(sky, 52);
|
|
407
|
-
const night = sunlight ? Math.max(0, Math.min(1, (3 - sunlight.altitude) / 9)) : 0;
|
|
408
|
-
frameData[55] = night * night * (3 - 2 * night);
|
|
409
|
-
frameData.set(sunlight?.tint || [1, 1, 1], 56);
|
|
410
|
-
frameData[59] = 0;
|
|
411
|
-
if (night > 0) backend._updatePointLights();
|
|
412
|
-
renderer.uniformSlot = 1;
|
|
413
|
-
backend._renderSunlight(encoder, shadowMeshes, sunlight);
|
|
414
|
-
const pass = encoder.beginRenderPass({
|
|
415
|
-
colorAttachments: [{
|
|
416
|
-
view: renderer.context.getCurrentTexture().createView(),
|
|
417
|
-
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
418
|
-
loadOp: 'clear',
|
|
419
|
-
storeOp: 'store',
|
|
420
|
-
}],
|
|
421
|
-
depthStencilAttachment: {
|
|
422
|
-
view: renderer.depthTexture.createView(),
|
|
423
|
-
depthClearValue: 1,
|
|
424
|
-
depthLoadOp: 'clear',
|
|
425
|
-
depthStoreOp: 'store',
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
pass.setViewport(0, 0, renderer.canvas.width, renderer.canvas.height, 0, 1);
|
|
429
|
-
pass.setBindGroup(1, renderer.sunlight.bindGroup);
|
|
430
|
-
for (const mesh of meshes) {
|
|
431
|
-
if (mesh.tile && mesh.tile.style.visibility !== 'hidden') pendingRasterTiles.push(mesh.tile);
|
|
432
|
-
const world = mesh.worldMatrix;
|
|
433
|
-
if (mesh.texture) {
|
|
434
|
-
mesh.program.uniforms.baseTexture.value = mesh.texture;
|
|
435
|
-
mesh.program.uniforms.opacity.value = mesh.opacity;
|
|
436
|
-
}
|
|
437
|
-
const uniforms = mesh.program.uniforms;
|
|
438
|
-
if (uniforms.roofTexture) uniforms.roofTexture.value = backend._roofRaster?.texture || renderer.roofFallbackTexture;
|
|
439
|
-
const determinant = world[0] * (world[5] * world[10] - world[6] * world[9]) -
|
|
440
|
-
world[4] * (world[1] * world[10] - world[2] * world[9]) +
|
|
441
|
-
world[8] * (world[1] * world[6] - world[2] * world[5]);
|
|
442
|
-
if (!Number.isFinite(determinant) || determinant === 0) {
|
|
443
|
-
throw new Error('Singular 3D transform');
|
|
444
|
-
}
|
|
445
|
-
const frontFace = determinant < 0 ? 'cw' : 'ccw';
|
|
446
|
-
const program = mesh.program;
|
|
447
|
-
if (program.transparent && program._layerMaterial.doubleSided) {
|
|
448
|
-
backend._drawGeometry(mesh, pass, 'front', frontFace);
|
|
449
|
-
backend._drawGeometry(mesh, pass, 'back', frontFace);
|
|
450
|
-
} else {
|
|
451
|
-
backend._drawGeometry(mesh, pass, program.cullMode, frontFace);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
pass.end();
|
|
455
|
-
renderer.device.queue.writeBuffer(renderer.uniformBuffer, 0, renderer.uniformData, 0, renderer.uniformSlot * 64);
|
|
456
|
-
renderer.device.queue.submit([encoder.finish()]);
|
|
457
|
-
if (pendingRasterTiles.length) {
|
|
458
|
-
renderer.device.queue.onSubmittedWorkDone().then(() => {
|
|
459
|
-
for (const tile of pendingRasterTiles) {
|
|
460
|
-
if (tile.isConnected && tile._terrainVisibility !== undefined) tile.style.visibility = 'hidden';
|
|
461
|
-
}
|
|
462
|
-
}, error => {
|
|
463
|
-
for (const layer of backend._layers || []) layer.fire('error', { error });
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
if (map._animatingZoom) backend.update();
|
|
467
|
-
}
|