You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
M3 MapLibre bridge: two-way interop between maplibre-gl-js and three.js #3
changed the title [-]M3 MapLibre bridge — two-way interop between maplibre-gl-js and three.js[/-][+]M3 MapLibre bridge: two-way interop between maplibre-gl-js and three.js[/+]on Sep 4, 2026
Kickoff plan for M3, now that #2, the vector tiles milestone, is closed.
What the custom layer actually hands us
Checked against maplibre-gl-js 5.24.0 source rather than assumed. A custom layer's render receives modelViewProjectionMatrix, projectionMatrix, nearZ, farZ, fov and defaultProjectionData every frame, and renderingMode: "3d" shares the map's depth buffer. MapLibre's own docs say a projection matrix alone is "sufficient for simple custom layers that also only support mercator projection", which is where both existing libraries stop.
Under globe, defaultProjectionData.mainMatrix projects a unit sphere planet, and MapLibre places a point on that sphere at x = sin(lng)cos(lat), y = sin(lat), z = cos(lng)cos(lat) (src/geo/projection/globe_utils.ts). This engine places it at x = cos(lon)cos(lat), y = sin(lat), z = -sin(lon)cos(lat). The two differ by a fixed 90 degree rotation about Y, so an ECEF scene maps into MapLibre's globe with one swizzle and a 1/R scale, with no shader surgery. MapLibre also hands over clippingPlane, which feeds straight into three.js renderer.clippingPlanes so nothing shows through the planet.
That is the thing worth building: a bridge that works on the globe, which neither of the two libraries in this space does.
Threebox is the richer object toolkit (loaders, shadows, drag, CSS2D labels) and is Mapbox only. maplibre-three-plugin is the closest neighbour and is flat map only.
The PRs
PR A, the bridge core.MapLibreLayer implementing CustomLayerInterface with renderingMode: "3d", a three.js renderer on MapLibre's own GL context with state reset per frame. Camera sync from the layer's matrices, mercator and globe, near, far and fov honoured. Scene space in meters around a floating origin, the trick the vector batches already use, so float32 holds at street level. Coordinate helpers both ways plus the mercator scale correction. Demo with a glTF model and MapAnchor on a MapLibre basemap, unit tests on the transforms, screenshots. The globe path is the risk in this milestone, so it is proven here or falls back to mercator with the reason written down.
PR B, terrain and ported examples. Anchors follow map.queryTerrainElevation and re-settle as terrain tiles arrive. Three MapLibre examples ported to the bridge (3D model on a map, animated line, custom layer), each a demo page with a screenshot.
PR C, direction B. The MapLibre basemap as an underlay inside this engine's own scene, one controller driving both. Two ways to do it, a DOM underlay or its canvas as a texture; the choice comes from measuring alignment error in pixels and the frame cost, not from taste.
PR D, the write-up and the API. The comparison above filled in with what was actually built, a typed API surface, docs, and an upstream contribution where one fits, most likely custom layer documentation for 3D content under globe.
Same working rules as M2: evidence with every PR, the benchmark and budget stay green, and nothing lands without a screenshot or a measurement behind it.
Five boxes ticked. Direction A, the coordinate utilities and the first ported examples landed in #17 (the custom layer, frames, 0.08 px against map.project()) and #20 (terrain, world space, the animated line and custom layer examples); direction B in #21 (MapLibre's map under our flat scene, 0.000 px) and #22 (the datum parameter, the scene on MapLibre's sphere under its globe, 0.000 px to zoom 7.6 and 0.25 px past 12). The camera sync contract is the underlay's: one controller, the map's camera derived from the scene's every frame, measured both ways by bridge-check and underlay-check. Left: the write-up against maplibre-gl-three, maplibre-three-plugin and threebox, and the typed API.
Last two boxes: the typed API and the comparison landed in #23 (types/index.d.ts checked by tsc in CI; the write-up in docs/design-notes.md, "Compared with threebox, maplibre-three-plugin and maplibre-gl-three"). What came out of it for later: a vertical datum (EGM96) for ECEF data, and a documentation contribution upstream on defaultProjectionData under globe, where none of the libraries handles the morph. Closing M3.
Activity
[-]M3 MapLibre bridge — two-way interop between maplibre-gl-js and three.js[/-][+]M3 MapLibre bridge: two-way interop between maplibre-gl-js and three.js[/+]clement-igonet commentedon Sep 27, 2026
Kickoff plan for M3, now that #2, the vector tiles milestone, is closed.
What the custom layer actually hands us
Checked against maplibre-gl-js 5.24.0 source rather than assumed. A custom layer's
renderreceivesmodelViewProjectionMatrix,projectionMatrix,nearZ,farZ,fovanddefaultProjectionDataevery frame, andrenderingMode: "3d"shares the map's depth buffer. MapLibre's own docs say a projection matrix alone is "sufficient for simple custom layers that also only support mercator projection", which is where both existing libraries stop.Under globe,
defaultProjectionData.mainMatrixprojects a unit sphere planet, and MapLibre places a point on that sphere atx = sin(lng)cos(lat),y = sin(lat),z = cos(lng)cos(lat)(src/geo/projection/globe_utils.ts). This engine places it atx = cos(lon)cos(lat),y = sin(lat),z = -sin(lon)cos(lat). The two differ by a fixed 90 degree rotation about Y, so an ECEF scene maps into MapLibre's globe with one swizzle and a 1/R scale, with no shader surgery. MapLibre also hands overclippingPlane, which feeds straight into three.jsrenderer.clippingPlanesso nothing shows through the planet.That is the thing worth building: a bridge that works on the globe, which neither of the two libraries in this space does.
Prior art, for the comparison task
MapScene,SceneTransform,Sun,CreatorThreebox is the richer object toolkit (loaders, shadows, drag, CSS2D labels) and is Mapbox only. maplibre-three-plugin is the closest neighbour and is flat map only.
The PRs
MapLibreLayerimplementingCustomLayerInterfacewithrenderingMode: "3d", a three.js renderer on MapLibre's own GL context with state reset per frame. Camera sync from the layer's matrices, mercator and globe, near, far and fov honoured. Scene space in meters around a floating origin, the trick the vector batches already use, so float32 holds at street level. Coordinate helpers both ways plus the mercator scale correction. Demo with a glTF model andMapAnchoron a MapLibre basemap, unit tests on the transforms, screenshots. The globe path is the risk in this milestone, so it is proven here or falls back to mercator with the reason written down.map.queryTerrainElevationand re-settle as terrain tiles arrive. Three MapLibre examples ported to the bridge (3D model on a map, animated line, custom layer), each a demo page with a screenshot.Same working rules as M2: evidence with every PR, the benchmark and budget stay green, and nothing lands without a screenshot or a measurement behind it.
clement-igonet commentedon Oct 3, 2026
Five boxes ticked. Direction A, the coordinate utilities and the first ported examples landed in #17 (the custom layer, frames, 0.08 px against
map.project()) and #20 (terrain, world space, the animated line and custom layer examples); direction B in #21 (MapLibre's map under our flat scene, 0.000 px) and #22 (the datum parameter, the scene on MapLibre's sphere under its globe, 0.000 px to zoom 7.6 and 0.25 px past 12). The camera sync contract is the underlay's: one controller, the map's camera derived from the scene's every frame, measured both ways bybridge-checkandunderlay-check. Left: the write-up against maplibre-gl-three, maplibre-three-plugin and threebox, and the typed API.clement-igonet commentedon Oct 4, 2026
Last two boxes: the typed API and the comparison landed in #23 (types/index.d.ts checked by tsc in CI; the write-up in docs/design-notes.md, "Compared with threebox, maplibre-three-plugin and maplibre-gl-three"). What came out of it for later: a vertical datum (EGM96) for ECEF data, and a documentation contribution upstream on
defaultProjectionDataunder globe, where none of the libraries handles the morph. Closing M3.