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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export async function loadImage(description, directory, image) {
|
|
2
|
+
let blob;
|
|
3
|
+
if (image.bufferView !== undefined) {
|
|
4
|
+
const view = description.bufferViews[image.bufferView];
|
|
5
|
+
const buffer = description.buffers[view.buffer].binary;
|
|
6
|
+
blob = new Blob([buffer.slice(view.byteOffset || 0, (view.byteOffset || 0) + view.byteLength)],
|
|
7
|
+
{ type: image.mimeType });
|
|
8
|
+
} else {
|
|
9
|
+
const response = await fetch(new URL(image.uri, directory).href);
|
|
10
|
+
if (!response.ok) throw new Error(`Unable to load model texture: HTTP ${response.status}`);
|
|
11
|
+
blob = await response.blob();
|
|
12
|
+
}
|
|
13
|
+
// Preserve straight alpha and raw samples; GPU sRGB formats do color decoding.
|
|
14
|
+
return createImageBitmap(blob, { premultiplyAlpha: 'none', colorSpaceConversion: 'none' });
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { decodeModel } from './decodeModel.js';
|
|
2
|
+
import { setParent } from '../scene/setParent.js';
|
|
3
|
+
import { emptyNode } from '../scene/emptyNode.js';
|
|
4
|
+
import { conformModelToTerrain } from '../geometry/conformModelToTerrain.js';
|
|
5
|
+
import { loadBuffer } from './loadBuffer.js';
|
|
6
|
+
import { loadImage } from './loadImage.js';
|
|
7
|
+
import { materialFor } from './materialFor.js';
|
|
8
|
+
import { modelNode } from './modelNode.js';
|
|
9
|
+
|
|
10
|
+
/** glTF/GLB model loading. */
|
|
11
|
+
/** Load the configured GLB/glTF (static triangles) under `root`; GPU resources need attachment. */
|
|
12
|
+
|
|
13
|
+
export async function loadModel(backend) {
|
|
14
|
+
await backend._added.promise;
|
|
15
|
+
const url = new URL(backend.modelUrl, document.baseURI).href;
|
|
16
|
+
const response = await fetch(url);
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw new Error(`Unable to load model: HTTP ${response.status}`);
|
|
19
|
+
}
|
|
20
|
+
const data = await response.arrayBuffer();
|
|
21
|
+
const description = decodeModel(data);
|
|
22
|
+
const directory = new URL('.', url).href;
|
|
23
|
+
const bufferRequests = [];
|
|
24
|
+
let buffer, image, material, index, resource, attribute, node;
|
|
25
|
+
for (buffer of description.buffers || []) bufferRequests.push(loadBuffer(buffer, directory));
|
|
26
|
+
await Promise.all(bufferRequests);
|
|
27
|
+
await backend._added.promise;
|
|
28
|
+
const imageRequests = [];
|
|
29
|
+
for (image of description.images || []) imageRequests.push(loadImage(description, directory, image));
|
|
30
|
+
const images = await Promise.all(imageRequests);
|
|
31
|
+
await backend._map?._terrain3D?._terrainPromise;
|
|
32
|
+
const context = { backend, description, images, textures: new Map(), materials: [], active: new Set(), resources: [] };
|
|
33
|
+
// Convert glTF materials directly to the shader's retained CPU styles.
|
|
34
|
+
for (material of description.materials || []) context.materials.push(materialFor(context, material));
|
|
35
|
+
const scene = description.scenes?.[description.scene || 0];
|
|
36
|
+
if (!scene) throw new Error('Missing glTF scene');
|
|
37
|
+
const nodes = [];
|
|
38
|
+
try {
|
|
39
|
+
for (index of scene.nodes) nodes.push(modelNode(context, index));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// Parsing can fail after earlier primitives allocated buffers/programs.
|
|
42
|
+
for (resource of context.resources) {
|
|
43
|
+
if (resource.attributes) {
|
|
44
|
+
for (attribute of Object.values(resource.attributes)) attribute.buffer.destroy();
|
|
45
|
+
} else {
|
|
46
|
+
resource.pipelineCache.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
const model = {
|
|
52
|
+
...emptyNode(),
|
|
53
|
+
id: url,
|
|
54
|
+
extras: description.extras || {},
|
|
55
|
+
};
|
|
56
|
+
if (!nodes.length) throw new Error('Expected a glTF model with a non-empty scene');
|
|
57
|
+
for (node of nodes) setParent(node, model);
|
|
58
|
+
backend.model = model;
|
|
59
|
+
if (backend.options.rotation) {
|
|
60
|
+
const [x, y = x, z = x] = backend.options.rotation;
|
|
61
|
+
backend.model.rotation[0] = x; backend.model.rotation[1] = y; backend.model.rotation[2] = z;
|
|
62
|
+
}
|
|
63
|
+
if (backend.options.scale) {
|
|
64
|
+
const [x, y = x, z = x] = backend.options.scale;
|
|
65
|
+
backend.model.scale[0] = x; backend.model.scale[1] = y; backend.model.scale[2] = z;
|
|
66
|
+
}
|
|
67
|
+
setParent(backend.model, backend.root);
|
|
68
|
+
conformModelToTerrain(backend, backend._map?._terrain3D);
|
|
69
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { textureFor } from './textureFor.js';
|
|
2
|
+
|
|
3
|
+
export function materialFor(context, material) {
|
|
4
|
+
const { backend } = context;
|
|
5
|
+
const pbr = material.pbrMetallicRoughness || {};
|
|
6
|
+
return {
|
|
7
|
+
color: (pbr.baseColorFactor || [1, 1, 1, 1]).slice(0, 3),
|
|
8
|
+
opacity: pbr.baseColorFactor?.[3] ?? 1,
|
|
9
|
+
metallic: pbr.metallicFactor ?? 1,
|
|
10
|
+
roughness: pbr.roughnessFactor ?? 1,
|
|
11
|
+
baseTexture: textureFor(context, pbr.baseColorTexture, true),
|
|
12
|
+
metalTexture: textureFor(context, pbr.metallicRoughnessTexture),
|
|
13
|
+
emissiveTexture: textureFor(context, material.emissiveTexture, true),
|
|
14
|
+
occlusionTexture: textureFor(context, material.occlusionTexture),
|
|
15
|
+
emissive: material.emissiveFactor || [0, 0, 0],
|
|
16
|
+
occlusionStrength: material.occlusionTexture?.strength ?? 1,
|
|
17
|
+
alphaMode: backend.options.alphaMode || material.alphaMode || 'OPAQUE',
|
|
18
|
+
alphaCutoff: material.alphaCutoff ?? 0.5,
|
|
19
|
+
doubleSided: material.doubleSided,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { cityMapper } from '../constants/cityMapper.js';
|
|
2
|
+
import { emptyNode } from '../scene/emptyNode.js';
|
|
3
|
+
import { nodeMatrix } from './nodeMatrix.js';
|
|
4
|
+
import { readAccessor } from './readAccessor.js';
|
|
5
|
+
import { setParent } from '../scene/setParent.js';
|
|
6
|
+
import { vertexNormals } from '../geometry/vertexNormals.js';
|
|
7
|
+
import { createProgram } from '../rendering/createProgram.js';
|
|
8
|
+
|
|
9
|
+
export function modelNode(context, index) {
|
|
10
|
+
const { backend, description, materials, active, resources } = context;
|
|
11
|
+
// Track only the recursion path: shared mesh references are valid, cycles are not.
|
|
12
|
+
if (active.has(index)) throw new Error('Cyclic glTF nodes');
|
|
13
|
+
const spec = description.nodes[index];
|
|
14
|
+
if (!spec) throw new Error('Invalid glTF node');
|
|
15
|
+
active.add(index);
|
|
16
|
+
const group = {
|
|
17
|
+
...emptyNode(),
|
|
18
|
+
name: spec.name
|
|
19
|
+
};
|
|
20
|
+
group.matrix = nodeMatrix(spec);
|
|
21
|
+
let primitive, attributes, semantic, name, vertexCount, attribute, index2, i, normals, style, program;
|
|
22
|
+
let device, geometry, mesh, child;
|
|
23
|
+
if (spec.mesh !== undefined) {
|
|
24
|
+
for (primitive of description.meshes[spec.mesh].primitives) {
|
|
25
|
+
attributes = {};
|
|
26
|
+
for ([semantic, name] of [['POSITION', 'position'], ['NORMAL', 'normal'], ['TEXCOORD_0', 'uv']]) {
|
|
27
|
+
if (primitive.attributes[semantic] !== undefined) attributes[name] = readAccessor(description, primitive.attributes[semantic]);
|
|
28
|
+
}
|
|
29
|
+
if (!attributes.position) throw new Error('glTF mesh has no positions');
|
|
30
|
+
vertexCount = attributes.position.data.length / 3;
|
|
31
|
+
if (attributes.position.size !== 3 || vertexCount < 3) throw new Error('Invalid glTF vertex attributes');
|
|
32
|
+
for (attribute of Object.values(attributes)) {
|
|
33
|
+
if (attribute.data.length / attribute.size !== vertexCount) throw new Error('Invalid glTF vertex attributes');
|
|
34
|
+
}
|
|
35
|
+
if (primitive.indices !== undefined) {
|
|
36
|
+
index2 = readAccessor(description, primitive.indices);
|
|
37
|
+
attributes.index = { size: 1, data: index2.indices };
|
|
38
|
+
if (!(index2.indices instanceof Uint8Array || index2.indices instanceof Uint16Array || index2.indices instanceof Uint32Array) ||
|
|
39
|
+
index2.size !== 1 || index2.indices.length % 3) throw new Error('Invalid glTF triangle indices');
|
|
40
|
+
for (i of index2.indices) {
|
|
41
|
+
if (i >= vertexCount) throw new Error('Invalid glTF triangle indices');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!attributes.index && vertexCount % 3) throw new Error('Incomplete glTF triangle');
|
|
45
|
+
if (!attributes.normal) {
|
|
46
|
+
normals = vertexNormals(attributes.position.data, attributes.index?.data);
|
|
47
|
+
attributes.normal = { size: 3, data: normals };
|
|
48
|
+
}
|
|
49
|
+
style = materials[primitive.material] || { color: [1, 1, 1], metallic: 1 };
|
|
50
|
+
if ((style.baseTexture || style.metalTexture || style.emissiveTexture || style.occlusionTexture) && !attributes.uv) {
|
|
51
|
+
throw new Error('Textured model mesh requires UV coordinates');
|
|
52
|
+
}
|
|
53
|
+
program = createProgram(backend, style);
|
|
54
|
+
resources.push(program);
|
|
55
|
+
device = backend.renderer.device;
|
|
56
|
+
if (attributes.index?.data instanceof Uint8Array) {
|
|
57
|
+
attributes.index.data = Uint16Array.from(attributes.index.data);
|
|
58
|
+
}
|
|
59
|
+
for ([name, attribute] of Object.entries(attributes)) {
|
|
60
|
+
attribute.size ||= 1;
|
|
61
|
+
attribute.count = attribute.data.length / attribute.size;
|
|
62
|
+
attribute.indexFormat = attribute.data instanceof Uint32Array ? 'uint32' : 'uint16';
|
|
63
|
+
attribute.buffer = device.createBuffer({
|
|
64
|
+
size: Math.max(4, attribute.data.byteLength),
|
|
65
|
+
usage: name === 'index'
|
|
66
|
+
? GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST
|
|
67
|
+
: GPUBufferUsage.VERTEX | GPUBufferUsage.COPY_DST,
|
|
68
|
+
});
|
|
69
|
+
device.queue.writeBuffer(attribute.buffer, 0, attribute.data);
|
|
70
|
+
}
|
|
71
|
+
geometry = {
|
|
72
|
+
device,
|
|
73
|
+
attributes,
|
|
74
|
+
drawRange: { start: 0, count: attributes.index?.count || attributes.position.count },
|
|
75
|
+
};
|
|
76
|
+
resources.push(geometry);
|
|
77
|
+
mesh = {
|
|
78
|
+
...emptyNode(),
|
|
79
|
+
device,
|
|
80
|
+
geometry,
|
|
81
|
+
program,
|
|
82
|
+
fadeDuration: 250,
|
|
83
|
+
id: cityMapper.nextId++,
|
|
84
|
+
renderOrder: 0
|
|
85
|
+
};
|
|
86
|
+
mesh.name = description.meshes[spec.mesh].name; mesh.extras = spec.extras || {};
|
|
87
|
+
setParent(mesh, group);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
for (child of spec.children || []) setParent(modelNode(context, child), group);
|
|
91
|
+
active.delete(index);
|
|
92
|
+
return group;
|
|
93
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** glTF quaternion/translation/scale to a column-major matrix. */
|
|
2
|
+
|
|
3
|
+
export function nodeMatrix(spec) {
|
|
4
|
+
if (spec.matrix) return Array.from(spec.matrix);
|
|
5
|
+
// glTF stores quaternions [x,y,z,w]; convert directly to a scaled column-major matrix.
|
|
6
|
+
const [x, y, z, w] = spec.rotation || [0, 0, 0, 1], [sx, sy, sz] = spec.scale || [1, 1, 1];
|
|
7
|
+
return [
|
|
8
|
+
(1 - 2 * (y * y + z * z)) * sx,
|
|
9
|
+
2 * (x * y + z * w) * sx,
|
|
10
|
+
2 * (x * z - y * w) * sx,
|
|
11
|
+
0,
|
|
12
|
+
2 * (x * y - z * w) * sy,
|
|
13
|
+
(1 - 2 * (x * x + z * z)) * sy,
|
|
14
|
+
2 * (y * z + x * w) * sy, 0,
|
|
15
|
+
2 * (x * z + y * w) * sz,
|
|
16
|
+
2 * (y * z - x * w) * sz,
|
|
17
|
+
(1 - 2 * (x * x + y * y)) * sz,
|
|
18
|
+
0,
|
|
19
|
+
...(spec.translation || [0, 0, 0]),
|
|
20
|
+
1,
|
|
21
|
+
];
|
|
22
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { types } from "../constants/accessorTypes.js";
|
|
2
|
+
import { sizes } from "../constants/accessorSizes.js";
|
|
3
|
+
import { readAccessorValues } from './readAccessorValues.js';
|
|
4
|
+
|
|
5
|
+
/** Decode packed, interleaved, normalized or sparse glTF accessor data. */
|
|
6
|
+
|
|
7
|
+
export function readAccessor(description, index) {
|
|
8
|
+
const spec = description.accessors[index], Type = types[spec.componentType], size = sizes[spec.type];
|
|
9
|
+
if (!Type || !size || !Number.isInteger(spec.count) || spec.count < 0) {
|
|
10
|
+
throw new Error('Invalid glTF accessor');
|
|
11
|
+
}
|
|
12
|
+
const data = new Type(spec.count * size);
|
|
13
|
+
if (spec.bufferView !== undefined) {
|
|
14
|
+
readAccessorValues(
|
|
15
|
+
description, Type, size, data, spec.count, null,
|
|
16
|
+
spec.bufferView,
|
|
17
|
+
spec.byteOffset || 0,
|
|
18
|
+
spec.count,
|
|
19
|
+
description.bufferViews[spec.bufferView].byteStride
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
if (spec.sparse) {
|
|
23
|
+
const sparse = spec.sparse, Index = types[sparse.indices.componentType];
|
|
24
|
+
if (![Uint8Array, Uint16Array, Uint32Array].includes(Index)) {
|
|
25
|
+
throw new Error('Invalid sparse glTF indices');
|
|
26
|
+
}
|
|
27
|
+
const view = description.bufferViews[sparse.indices.bufferView];
|
|
28
|
+
const offset = (view.byteOffset || 0) + (sparse.indices.byteOffset || 0);
|
|
29
|
+
if (sparse.count > spec.count || (sparse.indices.byteOffset || 0) + sparse.count * Index.BYTES_PER_ELEMENT > view.byteLength) {
|
|
30
|
+
throw new Error('Invalid sparse glTF indices');
|
|
31
|
+
}
|
|
32
|
+
const indices = new Index(description.buffers[view.buffer].binary.slice(offset, offset + sparse.count * Index.BYTES_PER_ELEMENT));
|
|
33
|
+
readAccessorValues(
|
|
34
|
+
description, Type, size, data, spec.count, indices,
|
|
35
|
+
sparse.values.bufferView,
|
|
36
|
+
sparse.values.byteOffset || 0,
|
|
37
|
+
sparse.count,
|
|
38
|
+
0
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (spec.componentType === 5126) {
|
|
42
|
+
return { data, size };
|
|
43
|
+
}
|
|
44
|
+
const normalized = new Float32Array(data.length);
|
|
45
|
+
// Normalization is a glTF accessor rule, not sRGB conversion; indices stay integers.
|
|
46
|
+
let i;
|
|
47
|
+
for (i = 0; i < data.length; i++) {
|
|
48
|
+
normalized[i] = spec.normalized
|
|
49
|
+
? Math.max(-1, data[i] / (Type === Int8Array ? 127 : Type === Int16Array ? 32767 : Type === Uint8Array ? 255 : Type === Uint32Array ? 4294967295 : 65535))
|
|
50
|
+
: data[i];
|
|
51
|
+
}
|
|
52
|
+
return { data: normalized, size, indices: data };
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function readAccessorValues(description, Type, size, data, accessorCount, indices, viewIndex, offset, count, stride) {
|
|
2
|
+
const view = description.bufferViews[viewIndex], bytes = Type.BYTES_PER_ELEMENT;
|
|
3
|
+
const buffer = description.buffers[view.buffer].binary;
|
|
4
|
+
stride ||= size * bytes;
|
|
5
|
+
if (!buffer || stride < size * bytes || offset < 0 ||
|
|
6
|
+
(view.byteOffset || 0) + view.byteLength > buffer.byteLength ||
|
|
7
|
+
(count - 1) * stride + size * bytes + offset > view.byteLength) throw new Error('glTF accessor outside buffer view');
|
|
8
|
+
let i, values, output;
|
|
9
|
+
for (i = 0; i < count; i++) {
|
|
10
|
+
values = new Type(buffer.slice((view.byteOffset || 0) + offset + i * stride,
|
|
11
|
+
(view.byteOffset || 0) + offset + i * stride + size * bytes));
|
|
12
|
+
output = indices ? indices[i] : i;
|
|
13
|
+
if (indices && output >= accessorCount) throw new Error('Invalid sparse glTF index');
|
|
14
|
+
data.set(values, output * size);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { textureSampler } from './textureSampler.js';
|
|
2
|
+
|
|
3
|
+
export function textureFor(context, reference, color = false) {
|
|
4
|
+
const { backend, description, images, textures } = context;
|
|
5
|
+
if (!reference) return null;
|
|
6
|
+
if ((reference.texCoord || 0) !== 0 || reference.extensions) {
|
|
7
|
+
throw new Error('Model textures currently require untransformed TEXCOORD_0 UVs');
|
|
8
|
+
}
|
|
9
|
+
const device = backend.renderer.device;
|
|
10
|
+
// A glTF image may serve both color and data maps: those cannot share a GPU format.
|
|
11
|
+
const key = `${reference.index}:${color}`;
|
|
12
|
+
if (!textures.has(key)) {
|
|
13
|
+
const texture = description.textures[reference.index];
|
|
14
|
+
const sampler = description.samplers?.[texture.sampler] || {};
|
|
15
|
+
const image = images[texture.source];
|
|
16
|
+
const format = color ? 'rgba8unorm-srgb' : 'rgba8unorm';
|
|
17
|
+
const samplerOptions = textureSampler(sampler);
|
|
18
|
+
textures.set(key, {
|
|
19
|
+
device,
|
|
20
|
+
texture: device.createTexture({
|
|
21
|
+
size: [image.width, image.height],
|
|
22
|
+
format,
|
|
23
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
|
|
24
|
+
}),
|
|
25
|
+
sampler: device.createSampler(samplerOptions),
|
|
26
|
+
samplerOptions,
|
|
27
|
+
format,
|
|
28
|
+
srgb: color,
|
|
29
|
+
image,
|
|
30
|
+
flipY: false,
|
|
31
|
+
uploaded: null,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return textures.get(key);
|
|
35
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Translate glTF sampler constants into WebGPU sampler options. */
|
|
2
|
+
|
|
3
|
+
export function textureSampler(sampler) {
|
|
4
|
+
return {
|
|
5
|
+
addressModeU: sampler.wrapS === 33071 ? 'clamp-to-edge' : sampler.wrapS === 33648 ? 'mirror-repeat' : 'repeat',
|
|
6
|
+
addressModeV: sampler.wrapT === 33071 ? 'clamp-to-edge' : sampler.wrapT === 33648 ? 'mirror-repeat' : 'repeat',
|
|
7
|
+
magFilter: sampler.magFilter === 9728 ? 'nearest' : 'linear',
|
|
8
|
+
minFilter: sampler.minFilter === 9728 || sampler.minFilter === 9984 || sampler.minFilter === 9986 ? 'nearest' : 'linear',
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { raycast } from './raycast.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Translate a geometry hit into a configured model or batched source feature.
|
|
5
|
+
* Sorted half-open face ranges permit binary search without a feature per triangle.
|
|
6
|
+
* @returns {PickedFeature|null}
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export function findFeature(backend, event) {
|
|
10
|
+
if (!backend.root || !backend.camera) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
let hit, object, ranges, low, high, middle, range;
|
|
14
|
+
for (hit of raycast(backend, event, backend.root.children, Boolean(backend.model))) {
|
|
15
|
+
if (backend.model) {
|
|
16
|
+
object = hit.object;
|
|
17
|
+
while (object && object !== backend.model) {
|
|
18
|
+
object = object.parent;
|
|
19
|
+
}
|
|
20
|
+
if (object === backend.model) {
|
|
21
|
+
return {
|
|
22
|
+
id: backend.model.id, properties: backend.model.extras,
|
|
23
|
+
model: backend.model, mesh: hit.object, point: hit.point
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
ranges = hit.object.extras?.featureFaces;
|
|
28
|
+
if (!ranges) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
low = 0, high = ranges.length - 1;
|
|
32
|
+
while (low <= high) {
|
|
33
|
+
middle = (low + high) >> 1;
|
|
34
|
+
range = ranges[middle];
|
|
35
|
+
if (hit.faceIndex < range.faceStart) {
|
|
36
|
+
high = middle - 1;
|
|
37
|
+
} else if (hit.faceIndex >= range.faceEnd) {
|
|
38
|
+
low = middle + 1;
|
|
39
|
+
} else {
|
|
40
|
+
return {
|
|
41
|
+
...range,
|
|
42
|
+
mesh: hit.object,
|
|
43
|
+
point: hit.point
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CELL } from '../constants/CELL.js';
|
|
2
|
+
import { collider } from '../collision/collider.js';
|
|
3
|
+
import { computeBounds } from '../geometry/computeBounds.js';
|
|
4
|
+
import { horizontalRay } from '../collision/horizontalRay.js';
|
|
5
|
+
import { traverse } from '../scene/traverse.js';
|
|
6
|
+
import { updateWorldMatrix } from '../scene/updateWorldMatrix.js';
|
|
7
|
+
import { shouldSkipOther } from './shouldSkipOther.js';
|
|
8
|
+
import { hitMesh } from './hitMesh.js';
|
|
9
|
+
|
|
10
|
+
// Horizontal normal of the nearest wall faced within `reach` metres of the feet at world (x, y, z), walking along
|
|
11
|
+
// the unit (dx, dz); knee and chest rays, so arches and tree crowns above the head let the walker through.
|
|
12
|
+
// ponytail: traffic vehicles and boats move on the GPU and are not obstacles.
|
|
13
|
+
|
|
14
|
+
export function hit(layer, x, y, z, dx, dz, reach) {
|
|
15
|
+
updateWorldMatrix(layer.scene);
|
|
16
|
+
const data = { x, y, z, dx, dz, reach, best: reach, found: null };
|
|
17
|
+
let other;
|
|
18
|
+
for (other of layer._shared._layers) {
|
|
19
|
+
if (shouldSkipOther(other, layer)) continue;
|
|
20
|
+
traverse(other.root, hitMesh, data);
|
|
21
|
+
}
|
|
22
|
+
return data.found;
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { computeBounds } from '../geometry/computeBounds.js';
|
|
2
|
+
import { collider } from '../collision/collider.js';
|
|
3
|
+
import { CELL } from '../constants/CELL.js';
|
|
4
|
+
import { horizontalRay } from '../collision/horizontalRay.js';
|
|
5
|
+
|
|
6
|
+
export function hitMesh(mesh, data) {
|
|
7
|
+
if (!mesh.visible) return true;
|
|
8
|
+
if (!mesh.geometry?.attributes?.position?.data || mesh.program?.depthTest === false) return;
|
|
9
|
+
if (!mesh.geometry.bounds) computeBounds(mesh.geometry);
|
|
10
|
+
const m = mesh.worldMatrix, { center: k, radius } = mesh.geometry.bounds;
|
|
11
|
+
const { x, y, z, dx, dz, reach } = data;
|
|
12
|
+
if (Math.hypot(m[0] * k[0] + m[4] * k[1] + m[8] * k[2] + m[12] - x, m[2] * k[0] + m[6] * k[1] + m[10] * k[2] + m[14] - z) >
|
|
13
|
+
radius * Math.hypot(m[0], m[1], m[2]) + reach) return;
|
|
14
|
+
const c = collider(mesh), ox = x - m[12] + c.origin[0], oy = y - m[13] + c.origin[1], oz = z - m[14] + c.origin[2];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
let ix, iz, t, height, d;
|
|
17
|
+
for (ix = Math.floor(Math.min(ox, ox + dx * reach) / CELL); ix <= Math.floor(Math.max(ox, ox + dx * reach) / CELL); ix++)
|
|
18
|
+
for (iz = Math.floor(Math.min(oz, oz + dz * reach) / CELL); iz <= Math.floor(Math.max(oz, oz + dz * reach) / CELL); iz++)
|
|
19
|
+
for (t of c.cells.get(ix + ',' + iz) || []) {
|
|
20
|
+
if (seen.has(t) || dx * c.nrm[t * 2] + dz * c.nrm[t * 2 + 1] >= 0) continue;
|
|
21
|
+
seen.add(t);
|
|
22
|
+
for (height of [0.4, 1.5]) {
|
|
23
|
+
d = horizontalRay(c.tri, t, ox, oy + height, oz, dx, dz);
|
|
24
|
+
if (d >= 0 && d < data.best) {
|
|
25
|
+
data.best = d;
|
|
26
|
+
data.found = [c.nrm[t * 2], c.nrm[t * 2 + 1]];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { findFeature } from './findFeature.js';
|
|
2
|
+
import { setHighlight } from './setHighlight.js';
|
|
3
|
+
import { showFeature } from './showFeature.js';
|
|
4
|
+
|
|
5
|
+
/** Emit click without moving the map or pinning the tooltip. */
|
|
6
|
+
|
|
7
|
+
export function onClick(layer, event) {
|
|
8
|
+
const feature = findFeature(layer, event);
|
|
9
|
+
layer.hoveredFeature = feature;
|
|
10
|
+
setHighlight(layer, feature);
|
|
11
|
+
showFeature(layer, feature, event);
|
|
12
|
+
layer.fire('featureclick', { feature, originalEvent: event });
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { setHighlight } from './setHighlight.js';
|
|
2
|
+
import { showFeature } from './showFeature.js';
|
|
3
|
+
|
|
4
|
+
/** Clear hover, highlight and tooltip without retaining a selected feature. */
|
|
5
|
+
|
|
6
|
+
export function onPointerLeave(layer) {
|
|
7
|
+
layer.hoveredFeature = null;
|
|
8
|
+
setHighlight(layer, null);
|
|
9
|
+
showFeature(layer, null);
|
|
10
|
+
layer.fire('featurehover', { feature: null });
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { findFeature } from './findFeature.js';
|
|
2
|
+
import { setHighlight } from './setHighlight.js';
|
|
3
|
+
import { showFeature } from './showFeature.js';
|
|
4
|
+
|
|
5
|
+
/** Hover is transient; featurehover also reports misses with feature:null. */
|
|
6
|
+
|
|
7
|
+
export function onPointerMove(layer, event) {
|
|
8
|
+
layer.hoveredFeature = findFeature(layer, event);
|
|
9
|
+
setHighlight(layer, layer.hoveredFeature);
|
|
10
|
+
showFeature(layer, layer.hoveredFeature, event);
|
|
11
|
+
layer.fire('featurehover', {
|
|
12
|
+
feature: layer.hoveredFeature,
|
|
13
|
+
originalEvent: event
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { intersectMeshes } from '../collision/intersectMeshes.js';
|
|
2
|
+
import { traverse } from '../scene/traverse.js';
|
|
3
|
+
import { updateCamera } from '../scene/updateCamera.js';
|
|
4
|
+
import { updateWorldMatrix } from '../scene/updateWorldMatrix.js';
|
|
5
|
+
import { collectVisibleMesh } from './collectVisibleMesh.js';
|
|
6
|
+
|
|
7
|
+
/** Raycasting, hover/click highlight and tooltips. */
|
|
8
|
+
/**
|
|
9
|
+
* Finds the objects under a mouse or pointer event, nearest first.
|
|
10
|
+
*
|
|
11
|
+
* @param {MouseEvent} event
|
|
12
|
+
* @param {Object[]} [objects] Defaults to this layer's root children, not all map layers.
|
|
13
|
+
* @param {boolean} [recursive] Also test the descendants of `objects`.
|
|
14
|
+
* @returns {Object[]} Nearest hit per mesh: object, shared-world point/distance and triangle faceIndex.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function raycast(backend, event, objects = backend.root.children, recursive = true) {
|
|
18
|
+
if (!backend.renderer) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
backend._beforeRaycast?.();
|
|
22
|
+
const rect = backend._map.getContainer().getBoundingClientRect();
|
|
23
|
+
updateWorldMatrix(backend.scene);
|
|
24
|
+
updateCamera(backend.camera);
|
|
25
|
+
// Unproject the mouse (-1..1) into a world-space ray from the camera.
|
|
26
|
+
const inverseCamera = new DOMMatrix(backend.camera.projectionViewMatrix).inverse();
|
|
27
|
+
const inverseCameraValues = inverseCamera.toFloat64Array();
|
|
28
|
+
let value, object;
|
|
29
|
+
for (value of inverseCameraValues) {
|
|
30
|
+
if (!Number.isFinite(value)) throw new Error('Singular 3D transform');
|
|
31
|
+
}
|
|
32
|
+
backend.raycaster.origin[0] = backend.camera.position[0];
|
|
33
|
+
backend.raycaster.origin[1] = backend.camera.position[1];
|
|
34
|
+
backend.raycaster.origin[2] = backend.camera.position[2];
|
|
35
|
+
const unprojected = new DOMPoint(
|
|
36
|
+
((event.clientX - rect.left) / rect.width) * 2 - 1,
|
|
37
|
+
-((event.clientY - rect.top) / rect.height) * 2 + 1,
|
|
38
|
+
0,
|
|
39
|
+
1
|
|
40
|
+
).matrixTransform(inverseCamera);
|
|
41
|
+
const end = [
|
|
42
|
+
unprojected.x / unprojected.w,
|
|
43
|
+
unprojected.y / unprojected.w,
|
|
44
|
+
unprojected.z / unprojected.w
|
|
45
|
+
];
|
|
46
|
+
backend.raycaster.direction[0] = end[0] - backend.raycaster.origin[0];
|
|
47
|
+
backend.raycaster.direction[1] = end[1] - backend.raycaster.origin[1];
|
|
48
|
+
backend.raycaster.direction[2] = end[2] - backend.raycaster.origin[2];
|
|
49
|
+
const rayLength = Math.hypot(...backend.raycaster.direction) || 1;
|
|
50
|
+
backend.raycaster.direction[0] /= rayLength;
|
|
51
|
+
backend.raycaster.direction[1] /= rayLength;
|
|
52
|
+
backend.raycaster.direction[2] /= rayLength;
|
|
53
|
+
const meshes = [];
|
|
54
|
+
for (object of objects) {
|
|
55
|
+
if (recursive) traverse(object, collectVisibleMesh, meshes);
|
|
56
|
+
else if (object.geometry && object.visible && object._appearance !== 0) meshes.push(object);
|
|
57
|
+
}
|
|
58
|
+
return intersectMeshes(backend.raycaster, meshes, backend.renderer.uniformData?.[55]);
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { update } from '../scene/update.js';
|
|
2
|
+
|
|
3
|
+
/** Highlight a source vertex range in the shader; vertex colors stay untouched. */
|
|
4
|
+
|
|
5
|
+
export function setHighlight(backend, feature) {
|
|
6
|
+
if (feature?.model) feature = null;
|
|
7
|
+
if (backend.highlightedFeature?.mesh === feature?.mesh &&
|
|
8
|
+
backend.highlightedFeature?.vertexStart === feature?.vertexStart) return;
|
|
9
|
+
if (backend.highlightedFeature) backend.highlightedFeature.mesh.highlight = null;
|
|
10
|
+
backend.highlightedFeature = feature;
|
|
11
|
+
if (feature) feature.mesh.highlight = [feature.vertexStart, feature.vertexEnd];
|
|
12
|
+
update(backend);
|
|
13
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Update tooltip content/position and arbitrate cursor ownership across shared layers. */
|
|
2
|
+
|
|
3
|
+
export function showFeature(backend, feature, event) {
|
|
4
|
+
const tooltip = backend._tooltip;
|
|
5
|
+
if (!tooltip) return;
|
|
6
|
+
if (feature) {
|
|
7
|
+
tooltip.replaceChildren(backend.options.tooltip(feature));
|
|
8
|
+
tooltip.hidden = false;
|
|
9
|
+
const rect = backend.container.getBoundingClientRect();
|
|
10
|
+
const x = event.clientX - rect.left, y = event.clientY - rect.top;
|
|
11
|
+
tooltip.style.left = `${x + tooltip.offsetWidth + 16 > rect.width ? x - tooltip.offsetWidth - 12 : x + 12}px`;
|
|
12
|
+
tooltip.style.top = `${y + tooltip.offsetHeight + 16 > rect.height ? y - tooltip.offsetHeight - 12 : y + 12}px`;
|
|
13
|
+
} else {
|
|
14
|
+
tooltip.hidden = true;
|
|
15
|
+
}
|
|
16
|
+
const shared = backend._shared;
|
|
17
|
+
let layer;
|
|
18
|
+
if (shared) {
|
|
19
|
+
let visible = false;
|
|
20
|
+
for (layer of shared._layers) {
|
|
21
|
+
if (layer._tooltip && !layer._tooltip.hidden) {
|
|
22
|
+
visible = true;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (visible) {
|
|
27
|
+
if (shared._cursor === undefined) shared._cursor = backend.container.style.cursor;
|
|
28
|
+
backend.container.style.cursor = 'pointer';
|
|
29
|
+
} else if (shared._cursor !== undefined) {
|
|
30
|
+
backend.container.style.cursor = shared._cursor;
|
|
31
|
+
delete shared._cursor;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|