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
|
@@ -1,237 +1,246 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@group(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
@
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@
|
|
43
|
-
@location(
|
|
44
|
-
@location(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
let
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
output.
|
|
68
|
-
|
|
69
|
-
${
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@group(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
@location(
|
|
122
|
-
@location(
|
|
123
|
-
@location(
|
|
124
|
-
@location(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
let
|
|
155
|
-
let
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
let
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let
|
|
205
|
-
let
|
|
206
|
-
let
|
|
207
|
-
let
|
|
208
|
-
let
|
|
209
|
-
let
|
|
210
|
-
let
|
|
211
|
-
let
|
|
212
|
-
let
|
|
213
|
-
let
|
|
214
|
-
let
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
${
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
1
|
+
import { textureBinding } from '../rendering/textureBinding.js';
|
|
2
|
+
|
|
3
|
+
/** Material WGSL and texture bindings, without a GPU device or Leaflet layer. */
|
|
4
|
+
export function materialShaders(material = {}, sparkle = false, elevationWGSL = '') {
|
|
5
|
+
const hasBase = Boolean(material.baseTexture);
|
|
6
|
+
const hasMetal = Boolean(material.metalTexture);
|
|
7
|
+
const hasEmissive = Boolean(material.emissiveTexture);
|
|
8
|
+
const hasOcclusion = Boolean(material.occlusionTexture);
|
|
9
|
+
const hasRoof = Boolean(material.roofTexture);
|
|
10
|
+
const hasTerrain = Boolean(material.terrain);
|
|
11
|
+
const textured = hasBase || hasMetal || hasEmissive || hasOcclusion || material.nightLight;
|
|
12
|
+
const vertex = /* wgsl */ `
|
|
13
|
+
struct Mesh {
|
|
14
|
+
worldMatrix: mat4x4<f32>,
|
|
15
|
+
baseColor: vec4<f32>,
|
|
16
|
+
material: vec4<f32>,
|
|
17
|
+
emissive: vec4<f32>,
|
|
18
|
+
terrain: vec4<f32>,
|
|
19
|
+
highlight: vec4<f32>,
|
|
20
|
+
};
|
|
21
|
+
struct Frame {
|
|
22
|
+
viewMatrix: mat4x4<f32>,
|
|
23
|
+
projectionMatrix: mat4x4<f32>,
|
|
24
|
+
roofMatrix: mat4x4<f32>,
|
|
25
|
+
lightDirection: vec4<f32>,
|
|
26
|
+
skyDirection: vec4<f32>,
|
|
27
|
+
atmosphereTint: vec4<f32>,
|
|
28
|
+
};
|
|
29
|
+
@group(0) @binding(0) var<uniform> u: Mesh;
|
|
30
|
+
@group(0) @binding(1) var<uniform> frame: Frame;
|
|
31
|
+
struct Solar { matrix: mat4x4<f32>, params: vec4<f32> };
|
|
32
|
+
@group(1) @binding(0) var<uniform> solar: Solar;
|
|
33
|
+
${hasTerrain ? /* wgsl */ `@group(0) @binding(2) var dem: texture_2d<f32>;${elevationWGSL}` : ''}
|
|
34
|
+
struct VertexInput {
|
|
35
|
+
@location(0) position: vec3<f32>,
|
|
36
|
+
@location(1) normal: vec3<f32>,
|
|
37
|
+
${material.instanced ? '@location(4) instanceOffset: vec4<f32>,' : ''}
|
|
38
|
+
${material.vertexColors ? '@location(2) color: vec3<f32>,' : ''}
|
|
39
|
+
${textured ? '@location(3) uv: vec2<f32>,' : ''}
|
|
40
|
+
};
|
|
41
|
+
struct VertexOutput {
|
|
42
|
+
@builtin(position) position: vec4<f32>,
|
|
43
|
+
@location(0) color: vec3<f32>,
|
|
44
|
+
@location(1) normal: vec3<f32>,
|
|
45
|
+
@location(2) viewPosition: vec3<f32>,
|
|
46
|
+
@location(6) shadowPosition: vec4<f32>,
|
|
47
|
+
@location(7) worldPosition: vec3<f32>,
|
|
48
|
+
${sparkle ? '@location(8) localPosition: vec3<f32>,' : ''}
|
|
49
|
+
${textured ? '@location(3) uv: vec2<f32>,' : ''}
|
|
50
|
+
${hasRoof ? '@location(4) roofUv: vec2<f32>, @location(5) roof: f32,' : ''}
|
|
51
|
+
};
|
|
52
|
+
@vertex fn vertexMain(input: VertexInput, @builtin(vertex_index) vertexIndex: u32) -> VertexOutput {
|
|
53
|
+
var output: VertexOutput;
|
|
54
|
+
var position = input.position${material.instanced ? ' + input.instanceOffset.xyz' : ''};
|
|
55
|
+
${hasTerrain ? 'position.y = elevation(u.terrain.xy + input.uv * u.terrain.z, u.terrain.w) - u.terrain.w;' : ''}
|
|
56
|
+
let featureVertex = f32(vertexIndex)${material.instanced ? ' + input.instanceOffset.w' : ''};
|
|
57
|
+
let highlighted = featureVertex >= u.highlight.x && featureVertex < u.highlight.y;
|
|
58
|
+
output.color = ${material.vertexColors
|
|
59
|
+
? 'select(input.color, vec3<f32>(72.0 / 255.0, 217.0 / 255.0, 1.0), highlighted)'
|
|
60
|
+
: 'u.baseColor.rgb'};
|
|
61
|
+
// Inverse-transpose from cofactors; the camera view matrix is orthonormal.
|
|
62
|
+
let m = mat3x3<f32>(u.worldMatrix[0].xyz, u.worldMatrix[1].xyz, u.worldMatrix[2].xyz);
|
|
63
|
+
let normal = (cross(m[1], m[2]) * input.normal.x + cross(m[2], m[0]) * input.normal.y +
|
|
64
|
+
cross(m[0], m[1]) * input.normal.z) / determinant(m);
|
|
65
|
+
output.normal = (frame.viewMatrix * vec4<f32>(normal, 0.0)).xyz;
|
|
66
|
+
let world = u.worldMatrix * vec4<f32>(position, 1.0);
|
|
67
|
+
output.shadowPosition = solar.matrix * world;
|
|
68
|
+
output.worldPosition = world.xyz / world.w;
|
|
69
|
+
${sparkle ? `output.localPosition = input.position${material.instanced ? ' + input.instanceOffset.xyz' : ''};` : ''}
|
|
70
|
+
let viewPosition = frame.viewMatrix * world;
|
|
71
|
+
output.viewPosition = viewPosition.xyz;
|
|
72
|
+
${textured ? 'output.uv = input.uv;' : ''}
|
|
73
|
+
${hasRoof ? /* wgsl */ `
|
|
74
|
+
output.roofUv = (frame.roofMatrix * world).xz;
|
|
75
|
+
output.roof = select(0.0, 1.0, input.normal.y >= 0.5 && !highlighted);
|
|
76
|
+
` : ''}
|
|
77
|
+
output.position = frame.projectionMatrix * viewPosition;
|
|
78
|
+
return output;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
const bindings = [];
|
|
82
|
+
const baseBinding = textureBinding(bindings, 'baseTexture', hasBase);
|
|
83
|
+
const metalBinding = textureBinding(bindings, 'metalTexture', hasMetal);
|
|
84
|
+
const emissiveBinding = textureBinding(bindings, 'emissiveTexture', hasEmissive);
|
|
85
|
+
const occlusionBinding = textureBinding(bindings, 'occlusionTexture', hasOcclusion);
|
|
86
|
+
const roofBinding = textureBinding(bindings, 'roofTexture', hasRoof);
|
|
87
|
+
const fragment = /* wgsl */ `
|
|
88
|
+
struct Mesh {
|
|
89
|
+
worldMatrix: mat4x4<f32>,
|
|
90
|
+
baseColor: vec4<f32>,
|
|
91
|
+
material: vec4<f32>,
|
|
92
|
+
emissive: vec4<f32>,
|
|
93
|
+
terrain: vec4<f32>,
|
|
94
|
+
highlight: vec4<f32>,
|
|
95
|
+
};
|
|
96
|
+
struct Frame {
|
|
97
|
+
viewMatrix: mat4x4<f32>,
|
|
98
|
+
projectionMatrix: mat4x4<f32>,
|
|
99
|
+
roofMatrix: mat4x4<f32>,
|
|
100
|
+
lightDirection: vec4<f32>,
|
|
101
|
+
skyDirection: vec4<f32>,
|
|
102
|
+
atmosphereTint: vec4<f32>,
|
|
103
|
+
};
|
|
104
|
+
struct Solar {
|
|
105
|
+
matrix: mat4x4<f32>,
|
|
106
|
+
params: vec4<f32>,
|
|
107
|
+
};
|
|
108
|
+
@group(0) @binding(0) var<uniform> u: Mesh;
|
|
109
|
+
@group(0) @binding(1) var<uniform> frame: Frame;
|
|
110
|
+
@group(1) @binding(0) var<uniform> solar: Solar;
|
|
111
|
+
@group(1) @binding(1) var shadowTexture: texture_depth_2d;
|
|
112
|
+
@group(1) @binding(2) var shadowSampler: sampler_comparison;
|
|
113
|
+
@group(1) @binding(3) var<storage, read> lightGrid: array<vec4<f32>>;
|
|
114
|
+
${baseBinding}${metalBinding}${emissiveBinding}${occlusionBinding}${roofBinding}
|
|
115
|
+
struct FragmentInput {
|
|
116
|
+
@builtin(position) position: vec4<f32>,
|
|
117
|
+
@location(0) color: vec3<f32>,
|
|
118
|
+
@location(1) normal: vec3<f32>,
|
|
119
|
+
@location(2) viewPosition: vec3<f32>,
|
|
120
|
+
@location(6) shadowPosition: vec4<f32>,
|
|
121
|
+
@location(7) worldPosition: vec3<f32>,
|
|
122
|
+
${sparkle ? '@location(8) localPosition: vec3<f32>,' : ''}
|
|
123
|
+
${textured ? '@location(3) uv: vec2<f32>,' : ''}
|
|
124
|
+
${hasRoof ? '@location(4) roofUv: vec2<f32>, @location(5) roof: f32,' : ''}
|
|
125
|
+
};
|
|
126
|
+
const PI: f32 = 3.14159265;
|
|
127
|
+
fn toLinear(c: vec3<f32>) -> vec3<f32> {
|
|
128
|
+
return select(c / 12.92, pow((c + vec3<f32>(0.055)) / 1.055, vec3<f32>(2.4)), c >= vec3<f32>(0.04045));
|
|
129
|
+
}
|
|
130
|
+
fn toSRGB(c: vec3<f32>) -> vec3<f32> {
|
|
131
|
+
return select(c * 12.92, 1.055 * pow(max(c, vec3<f32>(0.0)), vec3<f32>(1.0 / 2.4)) - vec3<f32>(0.055), c >= vec3<f32>(0.0031308));
|
|
132
|
+
}
|
|
133
|
+
fn sunVisibility(position: vec4<f32>) -> f32 {
|
|
134
|
+
let p = position.xyz / position.w;
|
|
135
|
+
let uv = vec2<f32>(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5);
|
|
136
|
+
if (solar.params.x < 0.5 || any(uv < vec2<f32>(0.0)) || any(uv > vec2<f32>(1.0)) || p.z < 0.0 || p.z > 1.0) {
|
|
137
|
+
return 1.0;
|
|
138
|
+
}
|
|
139
|
+
return textureSampleCompareLevel(shadowTexture, shadowSampler, uv, p.z - 0.0003);
|
|
140
|
+
}
|
|
141
|
+
fn gridLighting(position: vec3<f32>, normal: vec3<f32>, offset: u32) -> vec3<f32> {
|
|
142
|
+
let grid = lightGrid[offset];
|
|
143
|
+
if (grid.w < 1.0) { return vec3<f32>(0.0); }
|
|
144
|
+
let cell = vec2<i32>(floor((position.xz - grid.xy) / grid.z));
|
|
145
|
+
if (any(cell < vec2<i32>(0)) || cell.x >= i32(grid.w) || cell.y >= i32(lightGrid[offset + 1u].x)) {
|
|
146
|
+
return vec3<f32>(0.0);
|
|
147
|
+
}
|
|
148
|
+
let header = lightGrid[offset + 2u + u32(cell.y) * u32(grid.w) + u32(cell.x)];
|
|
149
|
+
var light = vec3<f32>(0.0);
|
|
150
|
+
for (var i = 0u; i < u32(header.y); i++) {
|
|
151
|
+
let source = lightGrid[offset + u32(header.x) + i * 2u];
|
|
152
|
+
let colour = lightGrid[offset + u32(header.x) + i * 2u + 1u];
|
|
153
|
+
let delta = source.xyz - position;
|
|
154
|
+
let distance2 = max(dot(delta, delta), 1.0);
|
|
155
|
+
let falloff = max(0.0, 1.0 - distance2 / (source.w * source.w));
|
|
156
|
+
let lambert = max(0.0, dot(normal, delta / sqrt(distance2)));
|
|
157
|
+
light += toLinear(colour.rgb) * colour.w * lambert * falloff * falloff / distance2;
|
|
158
|
+
}
|
|
159
|
+
return light;
|
|
160
|
+
}
|
|
161
|
+
fn localLighting(position: vec3<f32>, normal: vec3<f32>) -> vec3<f32> {
|
|
162
|
+
if (frame.skyDirection.w <= 0.0) { return vec3<f32>(0.0); }
|
|
163
|
+
var light = gridLighting(position, normal, 0u);
|
|
164
|
+
let moving = u32(lightGrid[1].z);
|
|
165
|
+
if (moving > 0u) { light += gridLighting(position, normal, moving); }
|
|
166
|
+
return light * frame.skyDirection.w;
|
|
167
|
+
}
|
|
168
|
+
fn appearance(position: vec2<f32>) {
|
|
169
|
+
// Screen-door dissolve keeps opaque depth writes and avoids sorting whole buildings as glass.
|
|
170
|
+
let noise = fract(52.9829189 * fract(dot(floor(position), vec2<f32>(0.06711056, 0.00583715))));
|
|
171
|
+
if (u.highlight.w < 1.0 && noise >= u.highlight.w) { discard; }
|
|
172
|
+
}
|
|
173
|
+
@fragment fn fragmentMain(input: FragmentInput, @builtin(front_facing) frontFacing: bool) -> @location(0) vec4<f32> {
|
|
174
|
+
${material.nightLight ? /* wgsl */ `
|
|
175
|
+
if (input.uv.x <= 2.0) {
|
|
176
|
+
let radial = max(0.0, 1.0 - dot(input.uv, input.uv));
|
|
177
|
+
let alpha = radial * radial * frame.skyDirection.w * 0.65;
|
|
178
|
+
if (alpha < 0.005) { discard; }
|
|
179
|
+
appearance(input.position.xy);
|
|
180
|
+
return vec4<f32>(input.color, alpha);
|
|
181
|
+
}
|
|
182
|
+
` : ''}
|
|
183
|
+
let sunlight = sunVisibility(input.shadowPosition);
|
|
184
|
+
let worldNormal = normalize(transpose(mat3x3<f32>(frame.viewMatrix[0].xyz, frame.viewMatrix[1].xyz, frame.viewMatrix[2].xyz)) * normalize(input.normal)) * select(-1.0, 1.0, frontFacing);
|
|
185
|
+
let artificial = localLighting(input.worldPosition, worldNormal);
|
|
186
|
+
${material.unlit ? /* wgsl */ `
|
|
187
|
+
let rasterTexel = ${hasBase ? 'textureSample(baseTexture, baseTextureSampler, input.uv)' : 'vec4<f32>(input.color, 1.0)'};
|
|
188
|
+
return vec4<f32>(toSRGB(toLinear(rasterTexel.rgb) * (frame.atmosphereTint.rgb * (0.55 + 0.45 * sunlight) + artificial)), ${material.alphaMode === 'BLEND' ? 'u.material.z * rasterTexel.a' : '1.0'});
|
|
189
|
+
` : /* wgsl */ `
|
|
190
|
+
var normal = normalize(input.normal) * select(-1.0, 1.0, frontFacing);
|
|
191
|
+
let texel = ${hasBase ? 'textureSample(baseTexture, baseTextureSampler, input.uv)' : 'vec4<f32>(1.0)'};
|
|
192
|
+
let alpha = u.material.z * texel.a;
|
|
193
|
+
${material.alphaMode === 'MASK' ? 'if (alpha < u.material.w) { discard; }' : ''}
|
|
194
|
+
${material.alphaMode === 'BLEND' ? 'if (alpha < 0.01) { discard; }' : ''}
|
|
195
|
+
var base = ${material.vertexColors ? 'toLinear(min(input.color, vec3<f32>(1.0)))' : 'input.color'} *
|
|
196
|
+
${material.baseTexture?.srgb ? 'texel.rgb' : 'toLinear(texel.rgb)'};
|
|
197
|
+
${hasRoof ? /* wgsl */ `
|
|
198
|
+
if (input.roof > 0.5 && all(input.roofUv >= vec2<f32>(0.0)) &&
|
|
199
|
+
all(input.roofUv <= vec2<f32>(1.0))) {
|
|
200
|
+
let roof = textureSampleLevel(roofTexture, roofTextureSampler, input.roofUv, 0.0);
|
|
201
|
+
base = mix(base, toLinear(roof.rgb), roof.a);
|
|
202
|
+
}
|
|
203
|
+
` : ''}
|
|
204
|
+
let mr = ${hasMetal ? 'textureSample(metalTexture, metalTextureSampler, input.uv)' : 'vec4<f32>(1.0)'};
|
|
205
|
+
let metal = clamp(u.material.x * mr.b, 0.0, 1.0);
|
|
206
|
+
let rough = clamp(u.material.y * mr.g, 0.08, 1.0);
|
|
207
|
+
let view = normalize(-input.viewPosition);
|
|
208
|
+
let halfVector = normalize(view + frame.lightDirection.xyz);
|
|
209
|
+
let nl = max(dot(normal, frame.lightDirection.xyz), 0.0) * frame.lightDirection.w * sunlight;
|
|
210
|
+
let nv = max(dot(normal, view), 0.001);
|
|
211
|
+
let nh = max(dot(normal, halfVector), 0.0);
|
|
212
|
+
let vh = max(dot(view, halfVector), 0.0);
|
|
213
|
+
let a2 = pow(rough, 4.0);
|
|
214
|
+
let d = a2 / max(PI * pow(nh * nh * (a2 - 1.0) + 1.0, 2.0), 0.0001);
|
|
215
|
+
let gv = nl * sqrt(nv * nv * (1.0 - a2) + a2);
|
|
216
|
+
let gl = nv * sqrt(nl * nl * (1.0 - a2) + a2);
|
|
217
|
+
let visibility = 0.5 / max(gv + gl, 0.0001);
|
|
218
|
+
let f0 = mix(vec3<f32>(0.04), base, metal);
|
|
219
|
+
let fresnel = f0 + (1.0 - f0) * pow(1.0 - vh, 5.0);
|
|
220
|
+
let specular = d * visibility * fresnel;
|
|
221
|
+
let diffuse = (1.0 - metal) * base / PI;
|
|
222
|
+
let sky = dot(normal, frame.skyDirection.xyz) * 0.5 + 0.5;
|
|
223
|
+
let ambient = mix(toLinear(vec3<f32>(0.455, 0.412, 0.322)), vec3<f32>(1.0), sky) * (2.0 / PI);
|
|
224
|
+
let ao = ${hasOcclusion ? 'mix(1.0, textureSample(occlusionTexture, occlusionTextureSampler, input.uv).r, u.emissive.w)' : '1.0'};
|
|
225
|
+
${sparkle ? /* wgsl */ `
|
|
226
|
+
let lattice = (fract(input.localPosition / 2.5) - 0.5) * 2.5;
|
|
227
|
+
let pointGlow = (1.0 - smoothstep(0.16, 0.42, length(lattice))) * u.highlight.z;
|
|
228
|
+
` : ''}
|
|
229
|
+
// Vertex colour components above 1 are self-lit (e.g. vehicle lamps): dim by day, bright at night.
|
|
230
|
+
let glow = ${sparkle ? 'vec3<f32>(3.0, 2.6, 1.8) * pointGlow +' : ''}${material.vertexColors
|
|
231
|
+
? ' max(input.color - vec3<f32>(1.0), vec3<f32>(0.0)) * (0.3 + 5.0 * frame.skyDirection.w) +' : ''} u.emissive.rgb * ${hasEmissive
|
|
232
|
+
? material.emissiveTexture.srgb
|
|
233
|
+
? 'textureSample(emissiveTexture, emissiveTextureSampler, input.uv).rgb'
|
|
234
|
+
: 'toLinear(textureSample(emissiveTexture, emissiveTextureSampler, input.uv).rgb)'
|
|
235
|
+
: 'vec3<f32>(1.0)'};
|
|
236
|
+
var color = ambient * base * (1.0 - metal) * ao +
|
|
237
|
+
(diffuse + specular) * nl * toLinear(vec3<f32>(1.0, 0.937, 0.835)) * 3.0 + glow;
|
|
238
|
+
${material.vertexColors ? 'color = base * (ambient + toLinear(vec3<f32>(1.0, 0.937, 0.835)) * (3.0 / PI) * nl) + glow;' : ''}
|
|
239
|
+
color = (color - glow) * frame.atmosphereTint.rgb + base * artificial * (1.0 - metal * 0.5) + glow;
|
|
240
|
+
appearance(input.position.xy);
|
|
241
|
+
return vec4<f32>(toSRGB(color), ${material.alphaMode === 'BLEND' ? 'alpha' : '1.0'});
|
|
242
|
+
`}
|
|
243
|
+
}
|
|
244
|
+
`;
|
|
245
|
+
return { vertex, fragment, bindings, textured, hasTerrain };
|
|
246
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
export function bindSunlight(layer) {
|
|
3
|
+
const sun = layer.renderer.sunlight;
|
|
4
|
+
sun.bindGroup = layer.renderer.device.createBindGroup({
|
|
5
|
+
layout: sun.layout, entries: [
|
|
6
|
+
{ binding: 0, resource: { buffer: sun.buffer } },
|
|
7
|
+
{ binding: 1, resource: sun.texture.createView() },
|
|
8
|
+
{ binding: 2, resource: sun.sampler },
|
|
9
|
+
{ binding: 3, resource: { buffer: sun.lights } },
|
|
10
|
+
]
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export function drawShadowMeshes(backend, encoder, meshes) {
|
|
2
|
+
const renderer = backend.renderer, device = renderer.device, sun = renderer.sunlight;
|
|
3
|
+
const pass = encoder.beginRenderPass({
|
|
4
|
+
colorAttachments: [],
|
|
5
|
+
depthStencilAttachment: {
|
|
6
|
+
view: sun.texture.createView(), depthClearValue: 1,
|
|
7
|
+
depthLoadOp: 'clear', depthStoreOp: 'store'
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
let pipeline = sun.pipeline;
|
|
11
|
+
pass.setPipeline(pipeline);
|
|
12
|
+
pass.setBindGroup(1, sun.depthBindGroup);
|
|
13
|
+
let mesh, instances, nextPipeline, offset, attribute, index, range;
|
|
14
|
+
for (mesh of meshes) {
|
|
15
|
+
instances = mesh.geometry.attributes.instanceOffset;
|
|
16
|
+
nextPipeline = instances ? sun.instancePipeline : sun.pipeline;
|
|
17
|
+
if (nextPipeline !== pipeline) {
|
|
18
|
+
pipeline = nextPipeline;
|
|
19
|
+
pass.setPipeline(pipeline);
|
|
20
|
+
}
|
|
21
|
+
offset = renderer.uniformSlot++ * 256;
|
|
22
|
+
renderer.uniformData.set(mesh.worldMatrix, offset / 4);
|
|
23
|
+
renderer.uniformData[offset / 4 + 35] = mesh._appearance ?? 1;
|
|
24
|
+
if (mesh._shadowBuffer !== renderer.uniformBuffer) {
|
|
25
|
+
mesh._shadowBuffer = renderer.uniformBuffer;
|
|
26
|
+
mesh._shadowBindGroup = device.createBindGroup({
|
|
27
|
+
layout: sun.meshLayout, entries: [
|
|
28
|
+
{ binding: 0, resource: { buffer: renderer.uniformBuffer, size: 144 } },
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
for (attribute of Object.values(mesh.geometry.attributes)) {
|
|
33
|
+
if (attribute.needsUpdate) {
|
|
34
|
+
device.queue.writeBuffer(attribute.buffer, 0, attribute.data);
|
|
35
|
+
attribute.needsUpdate = false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
pass.setBindGroup(0, mesh._shadowBindGroup, [offset]);
|
|
39
|
+
pass.setVertexBuffer(0, mesh.geometry.attributes.position.buffer);
|
|
40
|
+
if (instances) pass.setVertexBuffer(1, instances.buffer);
|
|
41
|
+
index = mesh.geometry.attributes.index, range = mesh.geometry.drawRange;
|
|
42
|
+
if (index) {
|
|
43
|
+
pass.setIndexBuffer(index.buffer, index.indexFormat);
|
|
44
|
+
pass.drawIndexed(range.count, instances?.count ?? 1, range.start, 0, 0);
|
|
45
|
+
} else pass.draw(range.count, instances?.count ?? 1, range.start, 0);
|
|
46
|
+
}
|
|
47
|
+
pass.end();
|
|
48
|
+
}
|