leaflet-city-mapper 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -13
- package/cucumber.mjs +4 -0
- package/dist/leaflet-city-mapper.js +3 -1
- package/dist/leaflet-city-mapper.js.map +4 -4
- package/package.json +3 -4
- package/src/archives/decodeDirectory.js +32 -0
- package/src/archives/decodeHeader.js +19 -0
- package/src/archives/decompress.js +5 -0
- package/src/archives/getHeader.js +9 -0
- package/src/archives/getZxy.js +75 -0
- package/src/archives/loadDirectory.js +7 -0
- package/src/archives/loadSource.js +17 -0
- package/src/archives/read.js +29 -0
- package/src/archives/tileId.js +19 -0
- package/src/archives/varint.js +15 -0
- package/src/camera/angles.js +6 -0
- package/src/camera/animationPoint.js +8 -0
- package/src/camera/cameraMapReady.js +8 -0
- package/src/camera/cancelCameraAnimation.js +11 -0
- package/src/camera/cleanupCameraMap.js +11 -0
- package/src/camera/constrainCameraToBounds.js +3 -0
- package/src/camera/displayPoint.js +3 -0
- package/src/camera/fitCameraBounds.js +48 -0
- package/src/camera/groundBounds.js +11 -0
- package/src/camera/initializeCameraMap.js +25 -0
- package/src/camera/mapAnimateCamera.js +17 -0
- package/src/camera/mapCamera.js +123 -0
- package/src/camera/mapContainerPointToLayerPoint.js +7 -0
- package/src/camera/mapGetBearing.js +1 -0
- package/src/camera/mapGetBounds.js +14 -0
- package/src/camera/mapGetBoundsCenterZoom.js +7 -0
- package/src/camera/mapGetBoundsZoom.js +14 -0
- package/src/camera/mapGetCenterLayerPoint.js +5 -0
- package/src/camera/mapGetPitch.js +1 -0
- package/src/camera/mapLayerPointToContainerPoint.js +7 -0
- package/src/camera/mapLimitCenter.js +12 -0
- package/src/camera/mapLimitOffset.js +10 -0
- package/src/camera/mapPanBy.js +9 -0
- package/src/camera/mapPanInside.js +14 -0
- package/src/camera/mapResetNorth.js +1 -0
- package/src/camera/mapResetNorthPitch.js +1 -0
- package/src/camera/mapSetBearing.js +1 -0
- package/src/camera/mapSetPitch.js +1 -0
- package/src/camera/mapSetPitchAndBearing.js +14 -0
- package/src/camera/mapSetZoomAround.js +11 -0
- package/src/camera/mapStopPitchBearingAnimation.js +6 -0
- package/src/camera/mapTryAnimatedPan.js +9 -0
- package/src/camera/mapUpdateCameraOverlays.js +7 -0
- package/src/camera/pointOf.js +3 -0
- package/src/camera/project.js +20 -0
- package/src/camera/runCameraAnimations.js +28 -0
- package/src/camera/scheduleCameraAnimation.js +8 -0
- package/src/camera/updateSky.js +16 -0
- package/src/camera/verticalGroundY.js +4 -0
- package/src/collision/collectMeshes.js +5 -0
- package/src/collision/collider.js +63 -0
- package/src/collision/horizontalRay.js +12 -0
- package/src/collision/intersectMeshes.js +133 -0
- package/src/collision/sortHits.js +23 -0
- package/src/constants/CELL.js +4 -0
- package/src/constants/Compass.js +7 -0
- package/src/constants/ContainerResize.js +7 -0
- package/src/constants/HEIGHT.js +1 -0
- package/src/constants/PitchDrag.js +7 -0
- package/src/constants/ShiftRotate.js +7 -0
- package/src/constants/TILE_RADIUS.js +1 -0
- package/src/constants/TILE_SIZE.js +1 -0
- package/src/constants/TouchMode.js +6 -0
- package/src/constants/accessorSizes.js +1 -0
- package/src/constants/accessorTypes.js +8 -0
- package/src/constants/attachState.js +1 -0
- package/src/constants/cameraControlsState.js +1 -0
- package/src/constants/cityMapper.js +6 -0
- package/src/constants/colliders.js +2 -0
- package/src/constants/dark.js +1 -0
- package/src/constants/elevationWGSL.js +27 -0
- package/src/constants/glass.js +1 -0
- package/src/constants/headlight.js +1 -0
- package/src/constants/hull.js +1 -0
- package/src/constants/indexState.js +1 -0
- package/src/constants/limbs.js +9 -0
- package/src/constants/mapCameraState.js +1 -0
- package/src/constants/moves.js +11 -0
- package/src/constants/nativeEventMaps.js +1 -0
- package/src/constants/nativeLayerState.js +1 -0
- package/src/constants/nativeMethodHandlers.js +31 -0
- package/src/constants/onMapChangeState.js +1 -0
- package/src/constants/onZoomAnimState.js +1 -0
- package/src/constants/paints.js +10 -0
- package/src/constants/parts.js +19 -0
- package/src/constants/pendingUpdates.js +1 -0
- package/src/constants/pumpState.js +1 -0
- package/src/constants/renderers.js +2 -0
- package/src/constants/ringDirections.js +10 -0
- package/src/constants/roundProfile.js +1 -0
- package/src/constants/shirt.js +1 -0
- package/src/constants/skin.js +2 -0
- package/src/constants/speed.js +3 -0
- package/src/constants/taillight.js +1 -0
- package/src/constants/trafficShader.js +49 -0
- package/src/constants/trousers.js +1 -0
- package/src/constants/tyre.js +1 -0
- package/src/constants/underEntryState.js +1 -0
- package/src/constants/vehicles.js +40 -0
- package/src/constants/white.js +1 -0
- package/src/controls/acceptPitchDrag.js +4 -0
- package/src/controls/acceptRotateDrag.js +3 -0
- package/src/controls/adjustCameraDrag.js +10 -0
- package/src/controls/cameraControls.js +60 -0
- package/src/controls/cameraDragClick.js +9 -0
- package/src/controls/cameraDragContextMenu.js +8 -0
- package/src/controls/cameraDragDown.js +20 -0
- package/src/controls/cameraDragEnd.js +6 -0
- package/src/controls/cameraDragMove.js +23 -0
- package/src/controls/changeCameraTouch.js +14 -0
- package/src/controls/cleanupCameraTouch.js +24 -0
- package/src/controls/compassAddHooks.js +15 -0
- package/src/controls/compassOrientation.js +6 -0
- package/src/controls/compassRemoveHooks.js +5 -0
- package/src/controls/containerResizeAddHooks.js +8 -0
- package/src/controls/containerResizeRemoveHooks.js +5 -0
- package/src/controls/dragCamera.js +22 -0
- package/src/controls/editable.js +3 -0
- package/src/controls/endAllCameraDrags.js +7 -0
- package/src/controls/endAllCameraTouches.js +7 -0
- package/src/controls/endCameraTouch.js +11 -0
- package/src/controls/endCameraTouchEvent.js +5 -0
- package/src/controls/finishCameraDrag.js +9 -0
- package/src/controls/finishCompassPermission.js +16 -0
- package/src/controls/loadCameraControls.js +9 -0
- package/src/controls/moveCameraTouch.js +22 -0
- package/src/controls/notifyCameraTouchChange.js +1 -0
- package/src/controls/pitchDragAddHooks.js +6 -0
- package/src/controls/pitchDragRemoveHooks.js +5 -0
- package/src/controls/refreshRotateControl.js +7 -0
- package/src/controls/refreshRotateFocus.js +5 -0
- package/src/controls/removeCameraDrag.js +23 -0
- package/src/controls/resizeMap.js +3 -0
- package/src/controls/rotateButtonClick.js +7 -0
- package/src/controls/rotateButtonKeydown.js +11 -0
- package/src/controls/rotateControl.js +3 -0
- package/src/controls/rotateOnAdd.js +38 -0
- package/src/controls/rotateOnRemove.js +6 -0
- package/src/controls/shiftRotateAddHooks.js +8 -0
- package/src/controls/shiftRotateRemoveHooks.js +5 -0
- package/src/controls/shiftRotateWheel.js +9 -0
- package/src/controls/startCameraTouch.js +23 -0
- package/src/core/addImageState.js +7 -0
- package/src/core/addRasterImage.js +10 -0
- package/src/core/adjustCameraMarkerPan.js +22 -0
- package/src/core/beforeNativeRender.js +10 -0
- package/src/core/boundsQuad.js +11 -0
- package/src/core/bringNativeLayerToBack.js +3 -0
- package/src/core/bringNativeLayerToFront.js +3 -0
- package/src/core/cameraCircleBounds.js +6 -0
- package/src/core/cameraMarkerDrag.js +18 -0
- package/src/core/cameraMarkerOnDrag.js +8 -0
- package/src/core/cancelGridFade.js +10 -0
- package/src/core/closestCameraLayerPoint.js +7 -0
- package/src/core/compareNativeHits.js +3 -0
- package/src/core/current.js +3 -0
- package/src/core/disposeNativeLayer.js +35 -0
- package/src/core/fireRasterLoad.js +5 -0
- package/src/core/forwardNativeError.js +3 -0
- package/src/core/gridlayerGetEvents.js +7 -0
- package/src/core/gridlayerGetTiledPixelBounds.js +8 -0
- package/src/core/handleNativeMapEvent.js +47 -0
- package/src/core/hideTargets.js +16 -0
- package/src/core/initNativeGPU.js +21 -0
- package/src/core/initializeGridContainer.js +6 -0
- package/src/core/initializeNativeLayer.js +42 -0
- package/src/core/localPixel.js +5 -0
- package/src/core/localPixelForGeometry.js +6 -0
- package/src/core/localPosition.js +6 -0
- package/src/core/markerCameraIconPoint.js +9 -0
- package/src/core/markerGetEvents.js +5 -0
- package/src/core/markerInitInteraction.js +8 -0
- package/src/core/markerQuadCorners.js +31 -0
- package/src/core/markerSetIcon.js +9 -0
- package/src/core/markerSetPos.js +14 -0
- package/src/core/markerSetRotation.js +7 -0
- package/src/core/markerUpdateZIndex.js +8 -0
- package/src/core/nativeAddLatLng.js +3 -0
- package/src/core/nativeBringToBack.js +3 -0
- package/src/core/nativeBringToFront.js +3 -0
- package/src/core/nativeEvents.js +26 -0
- package/src/core/nativeImageError.js +8 -0
- package/src/core/nativeImageRefresh.js +7 -0
- package/src/core/nativeLayer.js +97 -0
- package/src/core/nativeLayerMethod.js +21 -0
- package/src/core/nativeRedraw.js +3 -0
- package/src/core/nativeSetBounds.js +3 -0
- package/src/core/nativeSetIcon.js +3 -0
- package/src/core/nativeSetLatLng.js +3 -0
- package/src/core/nativeSetLatLngs.js +3 -0
- package/src/core/nativeSetOpacity.js +3 -0
- package/src/core/nativeSetRadius.js +3 -0
- package/src/core/nativeSetStyle.js +3 -0
- package/src/core/nativeSetUrl.js +3 -0
- package/src/core/nativeSetZIndex.js +3 -0
- package/src/core/nativeSetZIndexOffset.js +3 -0
- package/src/core/popupAdjustPan.js +23 -0
- package/src/core/popupGetEvents.js +5 -0
- package/src/core/popupUpdatePosition.js +14 -0
- package/src/core/putNativeMesh.js +33 -0
- package/src/core/quadNativeMesh.js +15 -0
- package/src/core/readyNativeGPU.js +6 -0
- package/src/core/refreshNativeEvent.js +5 -0
- package/src/core/refreshNativeLayer.js +29 -0
- package/src/core/refreshNativeLayerContract.js +3 -0
- package/src/core/rejectNativeReady.js +3 -0
- package/src/core/removeImageState.js +8 -0
- package/src/core/removeNativeEvents.js +16 -0
- package/src/core/removeTargets.js +8 -0
- package/src/core/reorderNativeLayer.js +6 -0
- package/src/core/resolveNativeReady.js +3 -0
- package/src/core/restoreNativeEvents.js +6 -0
- package/src/core/runGridFades.js +14 -0
- package/src/core/runMarkerPanFrame.js +12 -0
- package/src/core/scheduleGridFade.js +9 -0
- package/src/core/scheduleMarkerPan.js +8 -0
- package/src/core/styleNativeMesh.js +10 -0
- package/src/core/syncGridLayer.js +22 -0
- package/src/core/syncImageOverlay.js +9 -0
- package/src/core/syncMarker.js +12 -0
- package/src/core/syncVectorLayer.js +26 -0
- package/src/core/synchronizeNativeLayer.js +35 -0
- package/src/core/textureFor.js +48 -0
- package/src/core/tooltipGetEvents.js +5 -0
- package/src/core/tooltipSetPosition.js +8 -0
- package/src/core/updateGridOpacity.js +23 -0
- package/src/core/updateNativeLayerView.js +6 -0
- package/src/core/uploadCanvasTexture.js +19 -0
- package/src/geometry/addBridges.js +88 -0
- package/src/geometry/below.js +3 -0
- package/src/geometry/box.js +3 -0
- package/src/geometry/bridgeElevation.js +19 -0
- package/src/geometry/bridgeLocal.js +4 -0
- package/src/geometry/build.js +19 -0
- package/src/geometry/circleAt.js +5 -0
- package/src/geometry/clipLine.js +23 -0
- package/src/geometry/clipSegment.js +19 -0
- package/src/geometry/computeBounds.js +33 -0
- package/src/geometry/conformModelToTerrain.js +67 -0
- package/src/geometry/cross.js +3 -0
- package/src/geometry/disk.js +11 -0
- package/src/geometry/diskAt.js +4 -0
- package/src/geometry/dot.js +6 -0
- package/src/geometry/emitter.js +8 -0
- package/src/geometry/lampPostGeometry.js +24 -0
- package/src/geometry/lampRing.js +11 -0
- package/src/geometry/lightGeometry.js +15 -0
- package/src/geometry/line.js +54 -0
- package/src/geometry/nativeGeometry.js +55 -0
- package/src/geometry/nativeTriangle.js +3 -0
- package/src/geometry/polygon.js +22 -0
- package/src/geometry/push.js +3 -0
- package/src/geometry/quad.js +4 -0
- package/src/geometry/roofCoverage.js +52 -0
- package/src/geometry/samePoint.js +3 -0
- package/src/geometry/segment.js +21 -0
- package/src/geometry/setVertexColor.js +15 -0
- package/src/geometry/sub.js +6 -0
- package/src/geometry/surface.js +17 -0
- package/src/geometry/treeGeometry.js +31 -0
- package/src/geometry/treeRing.js +14 -0
- package/src/geometry/triangle.js +12 -0
- package/src/geometry/vertexNormals.js +32 -0
- package/src/geometry/visit.js +9 -0
- package/src/index.js +98 -65
- package/src/lighting/cacheLightGrid.js +23 -0
- package/src/lighting/collectLightMeshes.js +6 -0
- package/src/lighting/lightGrid.js +42 -0
- package/src/lighting/updatePointLights.js +34 -0
- package/src/lighting/visitCells.js +15 -0
- package/src/lighting/worldLights.js +27 -0
- package/src/models/decodeModel.js +45 -0
- package/src/models/hasUnsupportedPrimitives.js +10 -0
- package/src/models/loadBuffer.js +6 -0
- package/src/models/loadImage.js +15 -0
- package/src/models/loadModel.js +69 -0
- package/src/models/materialFor.js +21 -0
- package/src/models/modelNode.js +93 -0
- package/src/models/nodeMatrix.js +22 -0
- package/src/models/readAccessor.js +53 -0
- package/src/models/readAccessorValues.js +16 -0
- package/src/models/textureFor.js +35 -0
- package/src/models/textureSampler.js +10 -0
- package/src/picking/collectVisibleMesh.js +4 -0
- package/src/picking/findFeature.js +49 -0
- package/src/picking/hit.js +23 -0
- package/src/picking/hitMesh.js +30 -0
- package/src/picking/onClick.js +13 -0
- package/src/picking/onPointerLeave.js +11 -0
- package/src/picking/onPointerMove.js +15 -0
- package/src/picking/pointerClick.js +5 -0
- package/src/picking/pointerLeave.js +5 -0
- package/src/picking/pointerMove.js +5 -0
- package/src/picking/raycast.js +59 -0
- package/src/picking/setHighlight.js +13 -0
- package/src/picking/shouldSkipOther.js +3 -0
- package/src/picking/showFeature.js +34 -0
- package/src/raster/addRasterTile.js +114 -0
- package/src/raster/comparePendingTiles.js +5 -0
- package/src/raster/createGeometry.js +22 -0
- package/src/raster/createRasterMesh.js +47 -0
- package/src/raster/finishAttachment.js +11 -0
- package/src/raster/finishRasterTile.js +47 -0
- package/src/raster/getRasterEvents.js +6 -0
- package/src/raster/getRasterTileSize.js +5 -0
- package/src/raster/initRaster.js +38 -0
- package/src/raster/isLoading.js +5 -0
- package/src/raster/loadRasterTile.js +10 -0
- package/src/raster/onPMTileAdd.js +10 -0
- package/src/raster/onPMTileRemove.js +8 -0
- package/src/raster/pruneRasterTiles.js +37 -0
- package/src/raster/pumpRasterTiles.js +22 -0
- package/src/raster/readyRaster.js +13 -0
- package/src/raster/registerTerrainTile.js +12 -0
- package/src/raster/releaseRasterTile.js +18 -0
- package/src/raster/releaseRasterTiles.js +15 -0
- package/src/raster/removeRasterTile.js +13 -0
- package/src/raster/reportError.js +6 -0
- package/src/raster/setPMTileOpacity.js +7 -0
- package/src/raster/setPMTileZIndex.js +7 -0
- package/src/raster/setRasterOpacity.js +11 -0
- package/src/raster/setRasterTerrain.js +21 -0
- package/src/raster/setRasterZIndex.js +11 -0
- package/src/raster/updateAttachedTiles.js +10 -0
- package/src/raster/updateRasterTiles.js +59 -0
- package/src/rendering/collectFrameMeshes.js +31 -0
- package/src/rendering/collectMeshes.js +36 -0
- package/src/rendering/compareMeshes.js +10 -0
- package/src/rendering/compareRoofTiles.js +4 -0
- package/src/rendering/composeRoofAtlas.js +52 -0
- package/src/rendering/createMesh.js +33 -0
- package/src/rendering/createProgram.js +92 -0
- package/src/rendering/destroyAfterSubmission.js +8 -0
- package/src/rendering/destroyTexture.js +6 -0
- package/src/rendering/disposeMesh.js +14 -0
- package/src/rendering/drawGeometry.js +129 -0
- package/src/rendering/drawSceneMeshes.js +51 -0
- package/src/rendering/ensureRoofBlit.js +40 -0
- package/src/rendering/prepareFrameMeshes.js +42 -0
- package/src/rendering/prepareFrameUniforms.js +49 -0
- package/src/rendering/rebuildRoofAtlas.js +67 -0
- package/src/rendering/render.js +57 -0
- package/src/rendering/reportCompilation.js +17 -0
- package/src/rendering/resizeRenderer.js +19 -0
- package/src/rendering/sortMeshes.js +6 -0
- package/src/rendering/synchronizeZoomView.js +34 -0
- package/src/rendering/textureBinding.js +7 -0
- package/src/rendering/updateMapCamera.js +32 -0
- package/src/rendering/updateRoofRaster.js +32 -0
- package/src/scene/attach.js +161 -0
- package/src/scene/attachLayer.js +10 -0
- package/src/scene/cancelUpdate.js +10 -0
- package/src/scene/emptyEvents.js +3 -0
- package/src/scene/emptyNode.js +11 -0
- package/src/scene/endZoom.js +16 -0
- package/src/scene/failAttachment.js +9 -0
- package/src/scene/get3DEvents.js +13 -0
- package/src/scene/init3D.js +30 -0
- package/src/scene/initializeLayer.js +16 -0
- package/src/scene/initializerFor.js +14 -0
- package/src/scene/layerInitialize.js +38 -0
- package/src/scene/layerLayerAdd.js +21 -0
- package/src/scene/onAdd3DLayer.js +35 -0
- package/src/scene/onMapChange.js +16 -0
- package/src/scene/onRemove3DLayer.js +69 -0
- package/src/scene/onZoomAnim.js +16 -0
- package/src/scene/placeEntry.js +11 -0
- package/src/scene/placeUnderEntry.js +8 -0
- package/src/scene/ready3D.js +25 -0
- package/src/scene/releaseRenderer.js +14 -0
- package/src/scene/removeEntry.js +6 -0
- package/src/scene/renderPendingMapChange.js +11 -0
- package/src/scene/renderPendingUpdates.js +19 -0
- package/src/scene/renderPendingZoomAnimation.js +7 -0
- package/src/scene/rendererDeviceError.js +10 -0
- package/src/scene/rendererDeviceLost.js +11 -0
- package/src/scene/replaceEntry.js +7 -0
- package/src/scene/reportError.js +3 -0
- package/src/scene/requestAdapter.js +12 -0
- package/src/scene/requestDevice.js +9 -0
- package/src/scene/resolveNextInitialization.js +12 -0
- package/src/scene/restoreObject.js +71 -0
- package/src/scene/runPlacements.js +7 -0
- package/src/scene/setParent.js +7 -0
- package/src/scene/showWebGPUWarning.js +16 -0
- package/src/scene/startZoom.js +5 -0
- package/src/scene/traverse.js +7 -0
- package/src/scene/underEntry.js +17 -0
- package/src/scene/update.js +19 -0
- package/src/scene/updateCamera.js +34 -0
- package/src/scene/updateWorldMatrix.js +48 -0
- package/src/{utils/shaders.js → shaders/materialShaders.js} +246 -237
- package/src/shadows/bindSunlight.js +12 -0
- package/src/shadows/drawShadowMeshes.js +48 -0
- package/src/shadows/ensureShadowPipeline.js +53 -0
- package/src/shadows/renderSunlight.js +46 -0
- package/src/shadows/resizeSunlight.js +15 -0
- package/src/shadows/shadowBounds.js +32 -0
- package/src/shadows/shadowCacheMatches.js +23 -0
- package/src/shadows/shadowMatrix.js +39 -0
- package/src/sources/addGeneratedTriangle.js +6 -0
- package/src/sources/addTriangle.js +17 -0
- package/src/sources/attachAreaMesh.js +58 -0
- package/src/sources/buildArea.js +42 -0
- package/src/sources/buildAreaFeature.js +41 -0
- package/src/sources/buildAreaPoint.js +25 -0
- package/src/sources/buildAreaPolygon.js +29 -0
- package/src/sources/compareAreaDistance.js +4 -0
- package/src/sources/generateTreeGeometry.js +11 -0
- package/src/sources/groundOffset.js +3 -0
- package/src/sources/initializeGeoJSON.js +8 -0
- package/src/sources/instanceAreaGeometry.js +29 -0
- package/src/sources/projectRing.js +20 -0
- package/src/sources/projectedTree.js +13 -0
- package/src/sources/pump.js +54 -0
- package/src/sources/releaseArea.js +22 -0
- package/src/sources/setGeoJSONData.js +12 -0
- package/src/sources/setGeoJSONLayerData.js +5 -0
- package/src/sources/sourceAreaContext.js +9 -0
- package/src/sources/updateArea.js +45 -0
- package/src/sources/updateStatus.js +12 -0
- package/src/sunlight/addTimeLayer.js +3 -0
- package/src/sunlight/addTo.js +10 -0
- package/src/sunlight/atmosphere.js +28 -0
- package/src/sunlight/horizontalPosition.js +16 -0
- package/src/sunlight/initSunlight.js +14 -0
- package/src/sunlight/initialize.js +11 -0
- package/src/sunlight/mix.js +6 -0
- package/src/sunlight/moonPosition.js +17 -0
- package/src/sunlight/onAdd.js +5 -0
- package/src/sunlight/onAddSun.js +66 -0
- package/src/sunlight/projectCelestialBody.js +13 -0
- package/src/sunlight/remove.js +7 -0
- package/src/sunlight/removeSun.js +15 -0
- package/src/sunlight/removeTimeLayer.js +3 -0
- package/src/sunlight/render.js +7 -0
- package/src/sunlight/rgb.js +6 -0
- package/src/sunlight/solarPosition.js +17 -0
- package/src/sunlight/styleTimeControl.js +7 -0
- package/src/sunlight/tickSun.js +5 -0
- package/src/sunlight/updateSky.js +20 -0
- package/src/sunlight/updateSun.js +34 -0
- package/src/sunlight/useLiveTime.js +6 -0
- package/src/sunlight/useSelectedTime.js +20 -0
- package/src/terrain/clearLayerTerrain.js +5 -0
- package/src/terrain/getElevation.js +10 -0
- package/src/terrain/initTerrain.js +20 -0
- package/src/terrain/loadReadyTerrain.js +5 -0
- package/src/terrain/loadTerrain.js +63 -0
- package/src/terrain/loadTerrainTiles.js +13 -0
- package/src/terrain/onTerrainAdd.js +21 -0
- package/src/terrain/onTerrainChange.js +14 -0
- package/src/terrain/onTerrainRemove.js +41 -0
- package/src/terrain/readBridges.js +4 -0
- package/src/terrain/sample.js +7 -0
- package/src/terrain/setLayerTerrain.js +5 -0
- package/src/terrain/setTerrainHeight.js +10 -0
- package/src/terrain/terrainAtlas.js +23 -0
- package/src/terrain/terrainElevation.js +20 -0
- package/src/terrain/terrainGrid.js +24 -0
- package/src/traffic/addTraffic.js +7 -0
- package/src/traffic/along.js +14 -0
- package/src/traffic/clockMinutes.js +6 -0
- package/src/traffic/compareDepartures.js +5 -0
- package/src/traffic/createTrafficMesh.js +7 -0
- package/src/traffic/destroyTrafficGpu.js +5 -0
- package/src/traffic/disposeTrafficObject.js +13 -0
- package/src/traffic/drawTrafficRoute.js +6 -0
- package/src/traffic/failTraffic.js +6 -0
- package/src/traffic/failedTrafficLoad.js +5 -0
- package/src/traffic/fetchTrafficLanes.js +10 -0
- package/src/traffic/groundTraffic.js +15 -0
- package/src/traffic/initTraffic.js +54 -0
- package/src/traffic/loadTraffic.js +15 -0
- package/src/traffic/loadedTrafficLanes.js +16 -0
- package/src/traffic/locateTraffic.js +9 -0
- package/src/traffic/moveTraffic.js +15 -0
- package/src/traffic/placeTraffic.js +21 -0
- package/src/traffic/prepareTraffic.js +25 -0
- package/src/traffic/readyTraffic.js +6 -0
- package/src/traffic/rebaseTraffic.js +58 -0
- package/src/traffic/rebuildTrafficMesh.js +28 -0
- package/src/traffic/removeTraffic.js +17 -0
- package/src/traffic/routeColor.js +6 -0
- package/src/traffic/routeGeometry.js +31 -0
- package/src/traffic/scheduledTrips.js +40 -0
- package/src/traffic/startTraffic.js +8 -0
- package/src/traffic/tickTraffic.js +57 -0
- package/src/traffic/toLanes.js +16 -0
- package/src/traffic/tooltip.js +11 -0
- package/src/traffic/trafficBounds.js +17 -0
- package/src/traffic/trafficNow.js +4 -0
- package/src/traffic/trafficStorage.js +5 -0
- package/src/traffic/tripsAt.js +27 -0
- package/src/traffic/updateTraffic.js +8 -0
- package/src/traffic/updateTrafficTerrain.js +12 -0
- package/src/traffic/vehicleOffsets.js +11 -0
- package/src/triangulation/area.js +9 -0
- package/src/triangulation/clean.js +18 -0
- package/src/triangulation/containsVertex.js +11 -0
- package/src/triangulation/cross.js +3 -0
- package/src/triangulation/crossesBoundary.js +8 -0
- package/src/triangulation/crossesRing.js +9 -0
- package/src/triangulation/equal.js +3 -0
- package/src/triangulation/inside.js +10 -0
- package/src/triangulation/insideHole.js +7 -0
- package/src/triangulation/intersects.js +11 -0
- package/src/triangulation/isClockWise.js +13 -0
- package/src/triangulation/minimumX.js +6 -0
- package/src/triangulation/on.js +4 -0
- package/src/triangulation/sortHoles.js +26 -0
- package/src/triangulation/triangulate.js +86 -0
- package/src/utils/channel.js +4 -0
- package/src/utils/compareDistance.js +3 -0
- package/src/utils/noOperation.js +1 -0
- package/src/utils/parseColor.js +42 -0
- package/src/utils/toSRGB.js +3 -0
- package/src/utils/wrap.js +3 -0
- package/src/vehicles/bicycleModel.js +23 -0
- package/src/vehicles/boatBenches.js +8 -0
- package/src/vehicles/boatModel.js +27 -0
- package/src/vehicles/busModel.js +6 -0
- package/src/vehicles/carModel.js +22 -0
- package/src/vehicles/carriage.js +19 -0
- package/src/vehicles/metroModel.js +9 -0
- package/src/vehicles/mirror.js +8 -0
- package/src/vehicles/pedestrianModel.js +17 -0
- package/src/vehicles/tramModel.js +9 -0
- package/src/walk/blocked.js +6 -0
- package/src/walk/createWalk.js +60 -0
- package/src/walk/initWalk.js +18 -0
- package/src/walk/initialize.js +6 -0
- package/src/walk/local.js +10 -0
- package/src/walk/onAdd.js +4 -0
- package/src/walk/onBlur.js +3 -0
- package/src/walk/onKey.js +12 -0
- package/src/walk/onPointer.js +13 -0
- package/src/walk/onRemove.js +4 -0
- package/src/walk/onTerrain.js +5 -0
- package/src/walk/place.js +18 -0
- package/src/walk/start.js +37 -0
- package/src/walk/step.js +53 -0
- package/src/walk/stop.js +27 -0
- package/src/walk/toggle.js +6 -0
- package/dist/scene/gpu.js +0 -3
- package/dist/scene/gpu.js.map +0 -7
- package/dist/scene/lighting.js +0 -9
- package/dist/scene/lighting.js.map +0 -7
- package/dist/scene/model.js +0 -2
- package/dist/scene/model.js.map +0 -7
- package/dist/scene/picking.js +0 -2
- package/dist/scene/picking.js.map +0 -7
- package/dist/scene/pmtiles.js +0 -2
- package/dist/scene/pmtiles.js.map +0 -7
- package/dist/scene/render.js +0 -15
- package/dist/scene/render.js.map +0 -7
- package/dist/scene/sources.js +0 -2
- package/dist/scene/sources.js.map +0 -7
- package/dist/types/3d.js +0 -2
- package/dist/types/3d.js.map +0 -7
- package/dist/types/geojson.js +0 -2
- package/dist/types/geojson.js.map +0 -7
- package/dist/types/pmtiles.js +0 -2
- package/dist/types/pmtiles.js.map +0 -7
- package/dist/types/sunlight.js +0 -2
- package/dist/types/sunlight.js.map +0 -7
- package/dist/types/terrain.js +0 -24
- package/dist/types/terrain.js.map +0 -7
- package/dist/types/traffic.js +0 -41
- package/dist/types/traffic.js.map +0 -7
- package/dist/types/walk.js +0 -2
- package/dist/types/walk.js.map +0 -7
- package/dist/utils/control.js +0 -2
- package/dist/utils/control.js.map +0 -7
- package/dist/utils/geometry.js +0 -2
- package/dist/utils/geometry.js.map +0 -7
- package/dist/utils/lighting.js +0 -2
- package/dist/utils/lighting.js.map +0 -7
- package/dist/utils/model.js +0 -2
- package/dist/utils/model.js.map +0 -7
- package/dist/utils/picking.js +0 -2
- package/dist/utils/picking.js.map +0 -7
- package/dist/utils/pmtiles.js +0 -2
- package/dist/utils/pmtiles.js.map +0 -7
- package/dist/utils/scene.js +0 -2
- package/dist/utils/scene.js.map +0 -7
- package/dist/utils/shaders.js +0 -203
- package/dist/utils/shaders.js.map +0 -7
- package/dist/utils/sun.js +0 -2
- package/dist/utils/sun.js.map +0 -7
- package/dist/utils/terrain.js +0 -2
- package/dist/utils/terrain.js.map +0 -7
- package/dist/utils/traffic.js +0 -2
- package/dist/utils/traffic.js.map +0 -7
- package/dist/utils/vehicles.js +0 -2
- package/dist/utils/vehicles.js.map +0 -7
- package/dist/utils/walk.js +0 -2
- package/dist/utils/walk.js.map +0 -7
- package/src/scene/gpu.js +0 -438
- package/src/scene/lighting.js +0 -193
- package/src/scene/model.js +0 -204
- package/src/scene/picking.js +0 -150
- package/src/scene/pmtiles.js +0 -94
- package/src/scene/render.js +0 -467
- package/src/scene/sources.js +0 -265
- package/src/types/3d.js +0 -337
- package/src/types/geojson.js +0 -42
- package/src/types/pmtiles.js +0 -143
- package/src/types/sunlight.js +0 -142
- package/src/types/terrain.js +0 -331
- package/src/types/traffic.js +0 -356
- package/src/types/walk.js +0 -219
- package/src/utils/control.js +0 -18
- package/src/utils/geometry.js +0 -256
- package/src/utils/lighting.js +0 -51
- package/src/utils/model.js +0 -178
- package/src/utils/picking.js +0 -119
- package/src/utils/pmtiles.js +0 -79
- package/src/utils/scene.js +0 -102
- package/src/utils/sun.js +0 -71
- package/src/utils/terrain.js +0 -78
- package/src/utils/traffic.js +0 -90
- package/src/utils/vehicles.js +0 -69
- package/src/utils/walk.js +0 -72
package/src/utils/scene.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/** A fresh, empty scene-graph node. */
|
|
2
|
-
export const emptyNode = () => ({
|
|
3
|
-
position: [0, 0, 0],
|
|
4
|
-
rotation: [0, 0, 0],
|
|
5
|
-
scale: [1, 1, 1],
|
|
6
|
-
worldMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
|
7
|
-
children: [],
|
|
8
|
-
visible: true,
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
/** Reparent/detach scene data without drawing or disposing GPU resources. */
|
|
12
|
-
export function setParent(node, parent) {
|
|
13
|
-
if (node.parent) node.parent.children.splice(node.parent.children.indexOf(node), 1);
|
|
14
|
-
node.parent = parent;
|
|
15
|
-
if (parent) parent.children.push(node);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Depth-first walk; a truthy callback result skips that node's descendants. */
|
|
19
|
-
export function traverse(node, callback) {
|
|
20
|
-
if (callback(node)) return;
|
|
21
|
-
for (const child of node.children) traverse(child, callback);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Compose parent*local matrices; a node.matrix overrides its position/rotation/scale. */
|
|
25
|
-
export function updateWorldMatrix(node) {
|
|
26
|
-
const parent = node.parent;
|
|
27
|
-
const parentVersion = parent?._worldMatrixVersion || 0;
|
|
28
|
-
const matrixMode = Boolean(node.matrix);
|
|
29
|
-
let changed = node._worldParent !== parent || node._parentWorldVersion !== parentVersion ||
|
|
30
|
-
node._worldMatrixMode !== matrixMode;
|
|
31
|
-
if (node.matrix) {
|
|
32
|
-
const state = node._matrixState ||= new Float64Array(16);
|
|
33
|
-
for (let i = 0; i < 16; i++) {
|
|
34
|
-
if (state[i] !== node.matrix[i]) changed = true;
|
|
35
|
-
state[i] = node.matrix[i];
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
const state = node._transformState ||= new Float64Array(9);
|
|
39
|
-
for (let i = 0; i < 9; i++) {
|
|
40
|
-
const value = i < 3 ? node.position[i] : i < 6 ? node.rotation[i - 3] : node.scale[i - 6];
|
|
41
|
-
if (state[i] !== value) changed = true;
|
|
42
|
-
state[i] = value;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!changed) {
|
|
46
|
-
for (const child of node.children) updateWorldMatrix(child);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let local;
|
|
50
|
-
if (node.matrix) local = node.matrix;
|
|
51
|
-
else {
|
|
52
|
-
const degrees = 180 / Math.PI;
|
|
53
|
-
const matrix = new DOMMatrix().translate(...node.position);
|
|
54
|
-
// Node rotations use YXZ, as did the previous renderer.
|
|
55
|
-
matrix.rotateAxisAngleSelf(0, 1, 0, node.rotation[1] * degrees);
|
|
56
|
-
matrix.rotateAxisAngleSelf(1, 0, 0, node.rotation[0] * degrees);
|
|
57
|
-
matrix.rotateAxisAngleSelf(0, 0, 1, node.rotation[2] * degrees);
|
|
58
|
-
local = matrix.scale(...node.scale).toFloat64Array();
|
|
59
|
-
}
|
|
60
|
-
const world = parent
|
|
61
|
-
? new DOMMatrix(parent.worldMatrix).multiply(new DOMMatrix(local)).toFloat64Array()
|
|
62
|
-
: local;
|
|
63
|
-
for (let i = 0; i < 16; i++) node.worldMatrix[i] = world[i];
|
|
64
|
-
node._worldParent = parent;
|
|
65
|
-
node._parentWorldVersion = parentVersion;
|
|
66
|
-
node._worldMatrixMode = matrixMode;
|
|
67
|
-
node._worldMatrixVersion = (node._worldMatrixVersion || 0) + 1;
|
|
68
|
-
for (const child of node.children) updateWorldMatrix(child);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Orthonormal view basis plus perspective matrices, refreshed before projecting/drawing. */
|
|
72
|
-
export function updateCamera(camera) {
|
|
73
|
-
const z = camera.position.map((v, i) => v - camera.target[i]);
|
|
74
|
-
const zLength = Math.hypot(...z) || 1;
|
|
75
|
-
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
76
|
-
for (let i = 0; i < 3; i++) {
|
|
77
|
-
z[i] /= zLength;
|
|
78
|
-
}
|
|
79
|
-
const x = cross(camera.up, z), xLength = Math.hypot(...x) || 1;
|
|
80
|
-
for (let i = 0; i < 3; i++) {
|
|
81
|
-
x[i] /= xLength;
|
|
82
|
-
}
|
|
83
|
-
const y = cross(z, x);
|
|
84
|
-
const view = new DOMMatrix([x[0], x[1], x[2], 0, y[0], y[1], y[2], 0, z[0], z[1], z[2], 0, ...camera.position, 1]).inverse().toFloat64Array();
|
|
85
|
-
if (![...view].every(Number.isFinite)) {
|
|
86
|
-
throw new Error('Singular 3D transform');
|
|
87
|
-
}
|
|
88
|
-
for (let i = 0; i < 16; i++) {
|
|
89
|
-
camera.viewMatrix[i] = view[i];
|
|
90
|
-
}
|
|
91
|
-
const f = 1 / Math.tan(camera.fov * Math.PI / 360),
|
|
92
|
-
n = camera.near,
|
|
93
|
-
r = camera.far;
|
|
94
|
-
const projection = [f / camera.aspect, 0, 0, 0, 0, f, 0, 0, 0, 0, r / (n - r), -1, 0, 0, r * n / (n - r), 0];
|
|
95
|
-
for (let i = 0; i < 16; i++) {
|
|
96
|
-
camera.projectionMatrix[i] = projection[i];
|
|
97
|
-
}
|
|
98
|
-
const projectionView = new DOMMatrix(camera.projectionMatrix).multiply(new DOMMatrix(camera.viewMatrix)).toFloat64Array();
|
|
99
|
-
for (let i = 0; i < 16; i++) {
|
|
100
|
-
camera.projectionViewMatrix[i] = projectionView[i];
|
|
101
|
-
}
|
|
102
|
-
}
|
package/src/utils/sun.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// Solar centre, without atmospheric refraction.
|
|
2
|
-
export function solarPosition(date, lat, lng) {
|
|
3
|
-
const time = new Date(date).getTime();
|
|
4
|
-
if (!Number.isFinite(time) || !Number.isFinite(lat) || Math.abs(lat) > 90 ||
|
|
5
|
-
!Number.isFinite(lng) || Math.abs(lng) > 180) throw new Error('Invalid solar date or location');
|
|
6
|
-
const rad = Math.PI / 180, d = time / 86400000 - 10957.5;
|
|
7
|
-
const mean = (357.5291 + 0.98560028 * d) * rad;
|
|
8
|
-
const longitude = mean + (1.9148 * Math.sin(mean) + 0.02 * Math.sin(2 * mean) +
|
|
9
|
-
0.0003 * Math.sin(3 * mean) + 102.9372 + 180) * rad;
|
|
10
|
-
const obliquity = 23.4397 * rad;
|
|
11
|
-
const declination = Math.asin(Math.sin(longitude) * Math.sin(obliquity));
|
|
12
|
-
const ascension = Math.atan2(Math.sin(longitude) * Math.cos(obliquity), Math.cos(longitude));
|
|
13
|
-
return horizontalPosition(d, lat, lng, ascension, declination);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function horizontalPosition(d, lat, lng, ascension, declination) {
|
|
17
|
-
const rad = Math.PI / 180;
|
|
18
|
-
const hourAngle = (280.16 + 360.9856235 * d + lng) * rad - ascension;
|
|
19
|
-
const latitude = lat * rad;
|
|
20
|
-
const altitude = Math.asin(Math.sin(latitude) * Math.sin(declination) +
|
|
21
|
-
Math.cos(latitude) * Math.cos(declination) * Math.cos(hourAngle));
|
|
22
|
-
const southAzimuth = Math.atan2(Math.sin(hourAngle),
|
|
23
|
-
Math.cos(hourAngle) * Math.sin(latitude) - Math.tan(declination) * Math.cos(latitude));
|
|
24
|
-
const azimuth = (southAzimuth / rad + 180 + 360) % 360;
|
|
25
|
-
return { altitude: altitude / rad, azimuth,
|
|
26
|
-
direction: [Math.sin(azimuth * rad) * Math.cos(altitude), Math.sin(altitude),
|
|
27
|
-
-Math.cos(azimuth * rad) * Math.cos(altitude)] };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Low-precision geocentric lunar orbit; no parallax or atmospheric refraction.
|
|
31
|
-
export function moonPosition(date, lat, lng) {
|
|
32
|
-
solarPosition(date, lat, lng);
|
|
33
|
-
const rad = Math.PI / 180, d = new Date(date).getTime() / 86400000 - 10957.5;
|
|
34
|
-
const anomaly = (134.963 + 13.064993 * d) * rad;
|
|
35
|
-
const longitude = (218.316 + 13.176396 * d + 6.289 * Math.sin(anomaly)) * rad;
|
|
36
|
-
const latitude = 5.128 * Math.sin((93.272 + 13.229350 * d) * rad) * rad;
|
|
37
|
-
const obliquity = 23.4397 * rad;
|
|
38
|
-
const x = Math.cos(latitude) * Math.cos(longitude);
|
|
39
|
-
const y = Math.cos(latitude) * Math.sin(longitude) * Math.cos(obliquity) - Math.sin(latitude) * Math.sin(obliquity);
|
|
40
|
-
const z = Math.cos(latitude) * Math.sin(longitude) * Math.sin(obliquity) + Math.sin(latitude) * Math.cos(obliquity);
|
|
41
|
-
return horizontalPosition(d, lat, lng, Math.atan2(y, x), Math.asin(z));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function atmosphere(altitude) {
|
|
45
|
-
if (!Number.isFinite(altitude)) throw new Error('Invalid solar altitude');
|
|
46
|
-
const stops = [
|
|
47
|
-
[-18, [3, 7, 20], [17, 28, 54], [0.025, 0.04, 0.09]],
|
|
48
|
-
[-6, [37, 53, 84], [182, 106, 86], [0.12, 0.10, 0.14]],
|
|
49
|
-
[0, [101, 131, 171], [246, 170, 115], [0.38, 0.24, 0.18]],
|
|
50
|
-
[10, [74, 147, 208], [197, 221, 237], [0.80, 0.75, 0.68]],
|
|
51
|
-
[25, [53, 144, 213], [223, 238, 250], [1, 1, 1]],
|
|
52
|
-
];
|
|
53
|
-
const upper = stops.findIndex(stop => stop[0] >= altitude);
|
|
54
|
-
const b = stops[upper < 0 ? stops.length - 1 : upper], a = stops[Math.max(0, upper - 1)];
|
|
55
|
-
const t = a === b || upper < 0 ? 1 : (altitude - a[0]) / (b[0] - a[0]);
|
|
56
|
-
const mix = index => a[index].map((value, i) => value + (b[index][i] - value) * t);
|
|
57
|
-
const rgb = values => `rgb(${values.map(Math.round).join(', ')})`;
|
|
58
|
-
return { background: `linear-gradient(${rgb(mix(1))}, ${rgb(mix(2))})`, tint: mix(3) };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Perspective projection of a celestial direction; null when behind the camera. */
|
|
62
|
-
export function projectCelestialBody(direction, size, pitch, bearing) {
|
|
63
|
-
const [x, y, z] = direction;
|
|
64
|
-
const right = x * Math.cos(bearing) - z * Math.sin(bearing);
|
|
65
|
-
const up = -x * Math.sin(bearing) * Math.cos(pitch) + y * Math.sin(pitch) - z * Math.cos(bearing) * Math.cos(pitch);
|
|
66
|
-
const forward = -x * Math.sin(bearing) * Math.sin(pitch) - y * Math.cos(pitch) - z * Math.cos(bearing) * Math.sin(pitch);
|
|
67
|
-
if (forward <= 0) return null;
|
|
68
|
-
const left = size.x / 2 + size.y * 1.5 * right / forward;
|
|
69
|
-
const top = size.y / 2 - size.y * 1.5 * up / forward;
|
|
70
|
-
return { left, top };
|
|
71
|
-
}
|
package/src/utils/terrain.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/** Height inside a bridge deck, or null outside its triangles. */
|
|
2
|
-
export function bridgeElevation(point, bridges) {
|
|
3
|
-
// Bridges bucketed by 64 DEM pixels.
|
|
4
|
-
for (const bridge of bridges?.get(`${Math.floor(point.x / 64)}/${Math.floor(point.y / 64)}`) || []) {
|
|
5
|
-
if (point.x < bridge.min[0] || point.x > bridge.max[0] || point.y < bridge.min[1] || point.y > bridge.max[1]) continue;
|
|
6
|
-
for (const [a, b, c] of bridge.triangles) {
|
|
7
|
-
const d = (b[1] - c[1]) * (a[0] - c[0]) + (c[0] - b[0]) * (a[1] - c[1]);
|
|
8
|
-
const u = ((b[1] - c[1]) * (point.x - c[0]) + (c[0] - b[0]) * (point.y - c[1])) / d;
|
|
9
|
-
const v = ((c[1] - a[1]) * (point.x - c[0]) + (a[0] - c[0]) * (point.y - c[1])) / d;
|
|
10
|
-
if (u >= 0 && v >= 0 && u + v <= 1) return u * a[2] + v * b[2] + (1 - u - v) * c[2];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/** Bilinear DEM sampling, with the original first-valid-neighbour no-data rule. */
|
|
17
|
-
export function terrainElevation(point, tiles) {
|
|
18
|
-
const x = point.x - 0.5, y = point.y - 0.5;
|
|
19
|
-
const x0 = Math.floor(x), y0 = Math.floor(y);
|
|
20
|
-
const fx = x - x0, fy = y - y0;
|
|
21
|
-
const sample = (px, py) => {
|
|
22
|
-
const tileX = Math.floor(px / 256), tileY = Math.floor(py / 256);
|
|
23
|
-
const tile = tiles.get(`${tileX}/${tileY}`);
|
|
24
|
-
if (!tile) return null;
|
|
25
|
-
const elevation = tile[(py - tileY * 256) * 256 + px - tileX * 256];
|
|
26
|
-
return Number.isFinite(elevation) && elevation > -1000 ? elevation : null;
|
|
27
|
-
};
|
|
28
|
-
const values = [sample(x0, y0), sample(x0 + 1, y0), sample(x0, y0 + 1), sample(x0 + 1, y0 + 1)];
|
|
29
|
-
const valid = values.map((value, i) => Number.isFinite(value) ? i : -1).filter(i => i >= 0);
|
|
30
|
-
if (!valid.length) return null;
|
|
31
|
-
if (valid.length < 4) return values[valid[0]];
|
|
32
|
-
return (values[0] * (1 - fx) + values[1] * fx) * (1 - fy) +
|
|
33
|
-
(values[2] * (1 - fx) + values[3] * fx) * fy;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** Unit tile grid; the vertex shader supplies the elevation. */
|
|
37
|
-
export function terrainGrid(divisions) {
|
|
38
|
-
const positions = [], normals = [], uvs = [], indices = [];
|
|
39
|
-
for (let row = 0; row <= divisions; row++) {
|
|
40
|
-
for (let column = 0; column <= divisions; column++) {
|
|
41
|
-
positions.push(column / divisions, 0, row / divisions);
|
|
42
|
-
normals.push(0, 1, 0);
|
|
43
|
-
uvs.push(column / divisions, row / divisions);
|
|
44
|
-
if (row < divisions && column < divisions) {
|
|
45
|
-
const a = row * (divisions + 1) + column;
|
|
46
|
-
const b = a + 1, c = a + divisions + 1, d = c + 1;
|
|
47
|
-
indices.push(a, c, b, b, c, d);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
position: { size: 3, data: new Float32Array(positions) },
|
|
53
|
-
normal: { size: 3, data: new Float32Array(normals) },
|
|
54
|
-
uv: { size: 2, data: new Float32Array(uvs) },
|
|
55
|
-
index: { data: new Uint16Array(indices) },
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Float32 DEM atlas; missing samples retain the shader no-data sentinel. */
|
|
60
|
-
export function terrainAtlas(tiles, bounds) {
|
|
61
|
-
const columns = bounds.max.x - bounds.min.x + 1, rows = bounds.max.y - bounds.min.y + 1;
|
|
62
|
-
const elevations = new Float32Array(columns * rows * 65536).fill(-1e9);
|
|
63
|
-
let low = Infinity, high = -Infinity;
|
|
64
|
-
for (const [key, values] of tiles) {
|
|
65
|
-
const [x, y] = key.split('/').map(Number);
|
|
66
|
-
const start = (y - bounds.min.y) * 256 * columns * 256 + (x - bounds.min.x) * 256;
|
|
67
|
-
for (let row = 0; row < 256; row++) {
|
|
68
|
-
for (let column = 0; column < 256; column++) {
|
|
69
|
-
const value = values[row * 256 + column];
|
|
70
|
-
if (!Number.isFinite(value) || value <= -1000) continue;
|
|
71
|
-
elevations[start + row * columns * 256 + column] = value;
|
|
72
|
-
low = Math.min(low, value);
|
|
73
|
-
high = Math.max(high, value);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return { elevations, low, high };
|
|
78
|
-
}
|
package/src/utils/traffic.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// Pure helpers of the 'traffic' type: lane interpolation and vehicle scheduling.
|
|
2
|
-
|
|
3
|
-
/** Default urban speed (m/s) used to turn a lane's hourly `flow` into vehicles on the road. */
|
|
4
|
-
export const speed = 8;
|
|
5
|
-
|
|
6
|
-
/** Evenly spaced starting offsets (metres) for `flow` vehicles/h moving at `velocity` m/s on a `length` metres lane. */
|
|
7
|
-
export function vehicleOffsets(length, flow, velocity = speed) {
|
|
8
|
-
const count = Math.round(length * flow / 3600 / velocity);
|
|
9
|
-
return Array.from({ length: count }, (_, i) => (i + 0.5) * length / count);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Point and unit direction at distance `s` along `points` ([x, z, y?]) with cumulative `lengths`. */
|
|
13
|
-
export function along(points, lengths, s) {
|
|
14
|
-
let i = 1;
|
|
15
|
-
while (i < lengths.length - 1 && lengths[i] < s) i++;
|
|
16
|
-
const a = points[i - 1], b = points[i], d = lengths[i] - lengths[i - 1] || 1;
|
|
17
|
-
const t = (s - lengths[i - 1]) / d;
|
|
18
|
-
return { x: a[0] + (b[0] - a[0]) * t, y: (a[2] ?? 0) + ((b[2] ?? 0) - (a[2] ?? 0)) * t, z: a[1] + (b[1] - a[1]) * t, dx: (b[0] - a[0]) / d, dz: (b[1] - a[1]) / d };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Trips of a frequency-based timetable (like GTFS frequencies.txt) underway at `date`, in the timetable's local time.
|
|
23
|
-
* @param {{timeZone: string, duration: number, services: Array<{from: string, to: string, every?: number, months?: number[], weekdays?: number[]}>}} timetable
|
|
24
|
-
* `duration` and `every` are minutes; `from`/`to` are 'HH:MM' first/last departures; months are 1-12, weekdays 0 (Sunday)-6.
|
|
25
|
-
* @returns {Array<{id: string, departure: string, progress: number}>} `progress` is 0-1 along the lane.
|
|
26
|
-
*/
|
|
27
|
-
export function scheduledTrips(date, { timeZone, duration, services }) {
|
|
28
|
-
const time = new Date(date);
|
|
29
|
-
if (!Number.isFinite(time.getTime())) throw new Error('Invalid date');
|
|
30
|
-
const clock = new Intl.DateTimeFormat('en-GB', {
|
|
31
|
-
timeZone, year: 'numeric', month: '2-digit', day: '2-digit',
|
|
32
|
-
hour: '2-digit', minute: '2-digit', second: '2-digit', hourCycle: 'h23',
|
|
33
|
-
});
|
|
34
|
-
const parts = Object.fromEntries(clock.formatToParts(time).filter(p => p.type !== 'literal').map(p => [p.type, Number(p.value)]));
|
|
35
|
-
const minute = parts.hour * 60 + parts.minute + (parts.second + time.getUTCMilliseconds() / 1000) / 60;
|
|
36
|
-
const weekday = new Date(Date.UTC(parts.year, parts.month - 1, parts.day)).getUTCDay();
|
|
37
|
-
const minutes = clockTime => clockTime.split(':').reduce((hours, value) => hours * 60 + Number(value));
|
|
38
|
-
const departures = [];
|
|
39
|
-
for (const { from, to, every = Infinity, months, weekdays } of services) {
|
|
40
|
-
if (months?.includes(parts.month) === false || weekdays?.includes(weekday) === false) continue;
|
|
41
|
-
for (let departure = minutes(from); departure <= minutes(to); departure += every) departures.push(departure);
|
|
42
|
-
}
|
|
43
|
-
return departures.sort((a, b) => a - b).filter(departure => minute >= departure && minute < departure + duration).map(departure => ({
|
|
44
|
-
id: `${parts.year}-${parts.month}-${parts.day}-${departure}`,
|
|
45
|
-
departure: `${String(Math.floor(departure / 60)).padStart(2, '0')}:${String(departure % 60).padStart(2, '0')}`,
|
|
46
|
-
progress: (minute - departure) / duration,
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// GeoJSON (Multi)LineStrings become lanes ({latlngs, properties, elevation?}); prepare() adds `points` ([x, z, ground]),
|
|
51
|
-
// `lengths` and `length` in layer-local metres.
|
|
52
|
-
export const toLanes = ({ features = [] }) => features.flatMap(({ geometry, properties }) => {
|
|
53
|
-
const lines = geometry?.type === 'LineString' ? [geometry.coordinates] : geometry?.type === 'MultiLineString' ? geometry.coordinates : [];
|
|
54
|
-
return lines.map(line => ({ latlngs: line.map(([lng, lat]) => [lat, lng]), properties: properties ?? {}, elevation: properties?.elevation }));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// A lane with a `timetable` runs scheduled trips end to end; one with a `flow` (vehicles/h) loops evenly spaced vehicles.
|
|
58
|
-
export const tripsAt = (time, lanes, velocity) => lanes.flatMap((lane, l) => {
|
|
59
|
-
const { timetable, flow = 0 } = lane.properties;
|
|
60
|
-
if (!lane.length) return [];
|
|
61
|
-
if (timetable) return scheduledTrips(time, timetable).map(trip => ({
|
|
62
|
-
id: `${l}-${trip.id}`, lane, distance: trip.progress * lane.length, speed: lane.length / (timetable.duration * 60),
|
|
63
|
-
properties: { ...lane.properties, departure: trip.departure },
|
|
64
|
-
}));
|
|
65
|
-
const travelled = time / 1000 * velocity;
|
|
66
|
-
return (lane.offsets ||= vehicleOffsets(lane.length, flow, velocity))
|
|
67
|
-
.map((offset, k) => ({ id: `${l}-${k}`, lane, distance: (offset + travelled) % lane.length, speed: velocity, properties: lane.properties }));
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
/** Dashed lane outline, in layer-local metres. */
|
|
71
|
-
export function routeGeometry(lanes) {
|
|
72
|
-
const position = [], normal = [], color = [];
|
|
73
|
-
for (const { points, lengths } of lanes) for (let i = 1; i < points.length; i++) {
|
|
74
|
-
const a = points[i - 1], b = points[i];
|
|
75
|
-
const dx = b[0] - a[0], dz = b[1] - a[1], length = lengths[i] - lengths[i - 1];
|
|
76
|
-
if (!length) continue;
|
|
77
|
-
const x = -dz / length * 2.5, z = dx / length * 2.5;
|
|
78
|
-
for (let distance = Math.floor(lengths[i - 1] / 30) * 30; distance < lengths[i]; distance += 30) {
|
|
79
|
-
const start = Math.max(0, (distance - lengths[i - 1]) / length);
|
|
80
|
-
const end = Math.min(1, (distance + 18 - lengths[i - 1]) / length);
|
|
81
|
-
if (end <= start) continue;
|
|
82
|
-
const p = [a[0] + dx * start, a[1] + dz * start], q = [a[0] + dx * end, a[1] + dz * end], y = a[2] + 0.4;
|
|
83
|
-
for (const point of [[p[0] - x, p[1] - z], [p[0] + x, p[1] + z], [q[0] + x, q[1] + z],
|
|
84
|
-
[p[0] - x, p[1] - z], [q[0] + x, q[1] + z], [q[0] - x, q[1] - z]]) {
|
|
85
|
-
position.push(point[0], y, point[1]); normal.push(0, 1, 0); color.push(0.08, 0.7, 0.85);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return { position, normal, color };
|
|
90
|
-
}
|
package/src/utils/vehicles.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Built-in vehicles for the 'traffic' type. Models are [ring of [x, z], bottom, top, rgb, topRing?] convex prisms in metres;
|
|
2
|
-
// forward is -z, right is +x. `topRing` (same length as `ring`) tapers the prism; rgb components above 1 are self-lit lamps.
|
|
3
|
-
const paints = [[0.86, 0.86, 0.88], [0.1, 0.1, 0.12], [0.5, 0.53, 0.57], [0.65, 0.1, 0.08], [0.12, 0.25, 0.55], [0.85, 0.7, 0.15]];
|
|
4
|
-
export const box = (x0, x1, z0, z1) => [[x0, z0], [x1, z0], [x1, z1], [x0, z1]];
|
|
5
|
-
const mirror = (x0, x1, z0, z1, ...rest) => [[box(x0, x1, z0, z1), ...rest], [box(-x1, -x0, z0, z1), ...rest]];
|
|
6
|
-
const glass = [0.12, 0.15, 0.18], tyre = [0.05, 0.05, 0.05];
|
|
7
|
-
const headlight = [1.9, 1.85, 1.7], taillight = [1.7, 0.06, 0.05];
|
|
8
|
-
const car = i => {
|
|
9
|
-
const paint = paints[i % paints.length];
|
|
10
|
-
return [
|
|
11
|
-
...mirror(0.7, 0.92, -1.68, -1.02, 0, 0.64, tyre),
|
|
12
|
-
...mirror(0.7, 0.92, 1.02, 1.68, 0, 0.64, tyre),
|
|
13
|
-
[[[-0.9, -1.95], [-0.72, -2.25], [0.72, -2.25], [0.9, -1.95], [0.9, 2.05], [0.76, 2.25], [-0.76, 2.25], [-0.9, 2.05]],
|
|
14
|
-
0.28, 0.82, paint],
|
|
15
|
-
// Greenhouse: the windscreen leans back, the rear window less.
|
|
16
|
-
[box(-0.84, 0.84, -0.75, 1.6), 0.82, 1.38, glass, box(-0.7, 0.7, -0.05, 1.3)],
|
|
17
|
-
[box(-0.71, 0.71, -0.06, 1.31), 1.38, 1.46, paint],
|
|
18
|
-
...mirror(0.38, 0.8, -2.3, -2.16, 0.56, 0.76, headlight),
|
|
19
|
-
[box(-0.78, 0.78, 2.16, 2.3), 0.6, 0.76, taillight],
|
|
20
|
-
];
|
|
21
|
-
};
|
|
22
|
-
// Panoramic river cruiser, about 60 × 11 m: glass saloon, open upper deck with benches, wheelhouse forward.
|
|
23
|
-
const white = [0.92, 0.93, 0.92], hull = [[-5.5, 30], [5.5, 30], [5.5, -20], [4, -26], [1.5, -30], [-1.5, -30], [-4, -26], [-5.5, -20]];
|
|
24
|
-
const boat = () => [
|
|
25
|
-
[hull, 0, 0.8, [0.1, 0.16, 0.26]],
|
|
26
|
-
[hull, 0.8, 1.4, white],
|
|
27
|
-
[box(-5, 5, -18, 26), 1.4, 3.7, glass, box(-4.6, 4.6, -17.4, 25.6)],
|
|
28
|
-
...mirror(4.64, 4.74, -17, 25, 3.25, 3.45, [1.6, 1.25, 0.8]),
|
|
29
|
-
[box(-4.8, 4.8, -17.8, 25.8), 3.7, 3.9, white],
|
|
30
|
-
...Array.from({ length: 12 }, (_, i) => mirror(0.5, 3.8, -12 + i * 3, -11.3 + i * 3, 3.9, 4.4, [0.62, 0.1, 0.1])).flat(),
|
|
31
|
-
...mirror(4.65, 4.8, -13.6, 25.8, 3.9, 4.8, white),
|
|
32
|
-
[box(-4.8, 4.8, 25.65, 25.8), 3.9, 4.8, white],
|
|
33
|
-
[box(-2.2, 2.2, -17.6, -14), 3.9, 4.7, white],
|
|
34
|
-
[box(-2.2, 2.2, -17.6, -14), 4.7, 5.5, glass],
|
|
35
|
-
[box(-2.5, 2.5, -18, -13.6), 5.5, 5.7, white],
|
|
36
|
-
[box(-2.45, -2.2, -16.2, -15.8), 5, 5.3, [2, 0.15, 0.1]],
|
|
37
|
-
[box(2.2, 2.45, -16.2, -15.8), 5, 5.3, [0.1, 2, 0.4]],
|
|
38
|
-
[box(-0.1, 0.1, -15.9, -15.7), 5.7, 6.6, white],
|
|
39
|
-
[box(-0.15, 0.15, -15.95, -15.65), 6.6, 6.8, [2, 2, 1.9]],
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
export const build = parts => {
|
|
43
|
-
const position = [], normal = [], color = [];
|
|
44
|
-
const triangle = (a, b, c, tint) => {
|
|
45
|
-
const u = b.map((v, i) => v - a[i]), v = c.map((w, i) => w - a[i]);
|
|
46
|
-
const n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]], length = Math.hypot(...n);
|
|
47
|
-
for (const point of [a, b, c]) { position.push(...point); normal.push(...n.map(w => w / length)); color.push(...tint); }
|
|
48
|
-
};
|
|
49
|
-
for (const [ring, bottom, top, tint, topRing = ring] of parts) {
|
|
50
|
-
const low = ring.map(([x, z]) => [x, bottom, z]), high = topRing.map(([x, z]) => [x, top, z]);
|
|
51
|
-
for (let i = 0; i < ring.length; i++) {
|
|
52
|
-
const j = (i + 1) % ring.length;
|
|
53
|
-
triangle(low[i], low[j], high[j], tint); triangle(low[i], high[j], high[i], tint);
|
|
54
|
-
}
|
|
55
|
-
for (let i = 1; i < ring.length - 1; i++) {
|
|
56
|
-
triangle(high[0], high[i], high[i + 1], tint); triangle(low[0], low[i + 1], low[i], tint);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return { position, normal, color };
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* `side`: default offset (metres) to the right of the lane centreline. `model(i)` gives the prisms of the i-th vehicle.
|
|
64
|
-
* `lights`: night point lights in model space (see the night lighting grid), e.g. the pool cast by the headlights.
|
|
65
|
-
*/
|
|
66
|
-
export const vehicles = {
|
|
67
|
-
car: { side: 1.8, model: car, lights: [{ position: [0, 1.2, -6], radius: 10, color: [1, 0.94, 0.82], flux: 800 }] },
|
|
68
|
-
boat: { side: 0, model: boat, lights: [{ position: [0, 8, 4], radius: 30, color: [1, 0.8, 0.55], flux: 20000 }] },
|
|
69
|
-
};
|
package/src/utils/walk.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { box } from './vehicles.js';
|
|
2
|
-
|
|
3
|
-
// Pedestrian, about 1.77 m tall, prisms as in utils/vehicles.js (forward -z). Limbs hang from their pivot at y = 0.
|
|
4
|
-
const skin = [0.85, 0.64, 0.5], shirt = [0.75, 0.2, 0.15], trousers = [0.16, 0.2, 0.32], dark = [0.08, 0.07, 0.06];
|
|
5
|
-
export const parts = {
|
|
6
|
-
body: [
|
|
7
|
-
[box(-0.17, 0.17, -0.1, 0.1), 0.82, 0.95, trousers],
|
|
8
|
-
[box(-0.19, 0.19, -0.11, 0.11), 0.95, 1.44, shirt],
|
|
9
|
-
[box(-0.05, 0.05, -0.05, 0.05), 1.44, 1.5, skin],
|
|
10
|
-
[box(-0.1, 0.1, -0.11, 0.1), 1.5, 1.72, skin],
|
|
11
|
-
[box(-0.105, 0.105, -0.06, 0.115), 1.58, 1.77, dark],
|
|
12
|
-
[box(-0.105, 0.105, -0.115, -0.06), 1.7, 1.77, dark],
|
|
13
|
-
],
|
|
14
|
-
leg: [[box(-0.07, 0.07, -0.07, 0.07), -0.82, 0, trousers], [box(-0.07, 0.07, -0.17, 0.07), -0.9, -0.82, dark]],
|
|
15
|
-
arm: [[box(-0.05, 0.05, -0.05, 0.05), -0.55, 0, shirt], [box(-0.045, 0.045, -0.045, 0.045), -0.66, -0.55, skin]],
|
|
16
|
-
};
|
|
17
|
-
// [part, pivot x, pivot y, swing sign]
|
|
18
|
-
export const limbs = [['body', 0, 0, 0], ['leg', -0.09, 0.9, 1], ['leg', 0.09, 0.9, -1], ['arm', -0.25, 1.42, -1], ['arm', 0.25, 1.42, 1]];
|
|
19
|
-
// Walls (non-horizontal triangles) of a mesh in world space, bucketed by 8 m cells; `origin` is the world translation
|
|
20
|
-
// at build time, since layer roots only move vertically with the terrain afterwards.
|
|
21
|
-
export const CELL = 8;
|
|
22
|
-
const colliders = new WeakMap();
|
|
23
|
-
export function collider(mesh) {
|
|
24
|
-
let c = colliders.get(mesh.geometry);
|
|
25
|
-
if (c) return c;
|
|
26
|
-
const m = mesh.worldMatrix, { position: { data: p }, index, normal, uv } = mesh.geometry.attributes;
|
|
27
|
-
const count = index ? index.count : p.length / 3, tri = [], nrm = [], cells = new Map(), v = [];
|
|
28
|
-
for (let i = 0; i < count; i += 3) {
|
|
29
|
-
const first = index ? index.data[i] : i;
|
|
30
|
-
// Streetlight halos (uv.x <= 2, see scene/picking.js) are light, not matter.
|
|
31
|
-
if (mesh.program.nightLight && uv && uv.data[first * 2] <= 2) continue;
|
|
32
|
-
for (let k = 0; k < 3; k++) {
|
|
33
|
-
const j = (index ? index.data[i + k] : i + k) * 3, x = p[j], y = p[j + 1], z = p[j + 2];
|
|
34
|
-
v[k * 3] = m[0] * x + m[4] * y + m[8] * z + m[12];
|
|
35
|
-
v[k * 3 + 1] = m[1] * x + m[5] * y + m[9] * z + m[13];
|
|
36
|
-
v[k * 3 + 2] = m[2] * x + m[6] * y + m[10] * z + m[14];
|
|
37
|
-
}
|
|
38
|
-
const ex = v[3] - v[0], ey = v[4] - v[1], ez = v[5] - v[2], fx = v[6] - v[0], fy = v[7] - v[1], fz = v[8] - v[2];
|
|
39
|
-
let nx = ey * fz - ez * fy, nz = ex * fy - ey * fx;
|
|
40
|
-
const ny = ez * fx - ex * fz, length = Math.hypot(nx, ny, nz);
|
|
41
|
-
if (!length || Math.abs(ny) > 0.9 * length) continue;
|
|
42
|
-
if (normal) {
|
|
43
|
-
// The stored normal tells the outside, whatever the winding.
|
|
44
|
-
const j = first * 3, a = normal.data;
|
|
45
|
-
if ((m[0] * a[j] + m[4] * a[j + 1] + m[8] * a[j + 2]) * nx + (m[2] * a[j] + m[6] * a[j + 1] + m[10] * a[j + 2]) * nz < 0) { nx = -nx; nz = -nz; }
|
|
46
|
-
}
|
|
47
|
-
const h = Math.hypot(nx, nz), t = nrm.length / 2;
|
|
48
|
-
tri.push(...v); nrm.push(nx / h, nz / h);
|
|
49
|
-
for (let ix = Math.floor(Math.min(v[0], v[3], v[6]) / CELL); ix <= Math.floor(Math.max(v[0], v[3], v[6]) / CELL); ix++)
|
|
50
|
-
for (let iz = Math.floor(Math.min(v[2], v[5], v[8]) / CELL); iz <= Math.floor(Math.max(v[2], v[5], v[8]) / CELL); iz++) {
|
|
51
|
-
const key = ix + ',' + iz;
|
|
52
|
-
if (!cells.has(key)) cells.set(key, []);
|
|
53
|
-
cells.get(key).push(t);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
c = { tri: Float32Array.from(tri), nrm: Float32Array.from(nrm), cells, origin: [m[12], m[13], m[14]] };
|
|
57
|
-
colliders.set(mesh.geometry, c);
|
|
58
|
-
return c;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Möller-Trumbore for the horizontal ray (ox, oy, oz) + d·(dx, 0, dz) against triangle t; returns d or -1.
|
|
62
|
-
export function horizontalRay(v, t, ox, oy, oz, dx, dz) {
|
|
63
|
-
const i = t * 9, ex = v[i + 3] - v[i], ey = v[i + 4] - v[i + 1], ez = v[i + 5] - v[i + 2];
|
|
64
|
-
const fx = v[i + 6] - v[i], fy = v[i + 7] - v[i + 1], fz = v[i + 8] - v[i + 2];
|
|
65
|
-
const px = -dz * fy, py = dz * fx - dx * fz, pz = dx * fy, det = ex * px + ey * py + ez * pz;
|
|
66
|
-
if (Math.abs(det) < 1e-9) return -1;
|
|
67
|
-
const tx = ox - v[i], ty = oy - v[i + 1], tz = oz - v[i + 2], u = (tx * px + ty * py + tz * pz) / det;
|
|
68
|
-
if (u < 0 || u > 1) return -1;
|
|
69
|
-
const qx = ty * ez - tz * ey, qy = tz * ex - tx * ez, qz = tx * ey - ty * ex, w = (dx * qx + dz * qz) / det;
|
|
70
|
-
if (w < 0 || u + w > 1) return -1;
|
|
71
|
-
return (fx * qx + fy * qy + fz * qz) / det;
|
|
72
|
-
}
|