Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terrain rendering layer #1215

Closed
markov00 opened this issue Dec 5, 2017 · 19 comments
Closed

Terrain rendering layer #1215

markov00 opened this issue Dec 5, 2017 · 19 comments
Labels
Milestone

Comments

@markov00
Copy link

markov00 commented Dec 5, 2017

Hi, I was wondering if there is any future idea to support terrain rendering as a layer of deckgl.
The only useable solution for this type of rendering is Cesiumjs but I can't find any other libs with decent performances.
Any plan to include it in the feature releases?

@ibgreen
Copy link
Collaborator

ibgreen commented Dec 5, 2017

any future idea to support terrain rendering as a layer

@markov00 Are you talking about 3D terrain? It is a cool idea.

  • I suspect it would mostly be a question of having a good data set (i.e. 3D terrain information for the earth).
  • Do you have any information about what data Cesium is using?

@markov00
Copy link
Author

markov00 commented Dec 5, 2017

@ibgreen Yes was looking exactly at 3d terrain rendering.

Cesium is using the following terrain providers https://cesiumjs.org/data-and-assets/terrain/ but it's possible to use other terrain tile set like the one from mapbox mapbox.terrain-rgb used on this demo with threejs https://www.mapbox.com/bites/00332/#13.4682/36.3871/-112.6445/18.0142/30.5289

@markov00
Copy link
Author

markov00 commented Dec 5, 2017

There is also an issue open since 2015 in mapboxgl mapbox/mapbox-gl-js#1489 but seems that is something with low priority or quite complex to achieve

@howtimeflies0
Copy link

This would be super cool for tools we are building internally as well.... imagine the terrain of SF... :)

@markov00
Copy link
Author

markov00 commented Dec 5, 2017

One of the possible problems is how to handle map elements like roads, labels and any other object. They are currently clamped to the ground.
Cesium have the possibility to "clamptoground" a geojson feature or a marker on a terrain mesh: when the terrain tile is loaded and rendered, everything that is on the tile space change it's height in relation to the tile shape.
But this is something that needs to be handled either on mapbox side and on deckgl side

@jianhuang01 jianhuang01 added this to the Backlog milestone Jan 25, 2018
@pwilczynski
Copy link

We've been working internally on some tools for using Cesium + Mapbox together and swapping libraries to jump between 2d/3d. Would love to hear more about how other people are approaching it. The main missing piece is around MVT support, which doesn't exist in cesium right now as far as we can tell.

@tmaiaroto
Copy link

I've used three.js in the past with bump/height mapping. I did a small experiment with D3.js, three.js and rendering a state (california) and then extruding it. Then to that, add mapping with a black/white image (low resolution). Here's an early rendering of what I was doing (sans height map): https://pbs.twimg.com/media/CsBMIlwVMAA258s.jpg

I found a few people doing the same and used parts of their research/code.
http://blog.mastermaps.com/2013/10/terrain-building-with-threejs-part-1.html
https://github.com/meetar/heightmap-demos

The challenge, for me, was finding high enough resolution height map imagery. Awesome to know mapbox has basically a tile server equivalent for elevation maps. That didn't exist before. This is probably one of the biggest hurdles.

This is definitely something I'm interested in too and given the limited time I have right now and the heavy lifting Uber has done here already...I'm likely going to look to do this again using deck.gl. I have no interest in hobbled together three.js + d3.js when there's a framework here that will help me put this into production faster. Though for me, I do want to see if it's possible to just render an isolated state/region with geojson. I like the idea of an "illustration" more than a "map" if that makes sense. I don't want to see everything around what I'm visualizing and I don't want the fidelity of roads, etc. Maybe just mountains and streams and a few city labels.

I'll follow along here and if by chance I make any progress before anyone else (slim chance), I'll also post back and share. Maybe the above links help someone.

@chrisgervang
Copy link
Collaborator

chrisgervang commented Mar 10, 2018

The challenge, for me, was finding high enough resolution height map imagery.

I agree. I haven't spent a lot of time trying the mapbox datasets, but I'm eventually going to work something that converts them to height map images like the kind used in the deck.gl elevation layer. For now, I've only made height maps with some internal data.

But that test proved to me this layer is definitely good enough to be a starting point for a terrain layer. I modified it a bit in december and got a nice result. If folks are interested, I can probably put together a PR for the modifications I used. I'd argue until we have the function that converts mapbox data to the right kind of image, the deck.gl layer isn't super duper useful, but I believe this function is possible to make.

@tmaiaroto
Copy link

If you're able to, that'd be awesome. I'd love to see how it works. Even if it's a whole new layer and not so much a PR. I don't know how it works or what makes sense. If it's really that close to working that it's more of a small addition to the layer than a brand new one in its own right, that sounds even nicer.

@mogmog
Copy link

mogmog commented Mar 25, 2019

This would be amazing, did any progress get made on it?

@kylebarron
Copy link
Collaborator

kylebarron commented Dec 12, 2019

I've been doing some research on this...

Mapbox's Terrain RGB tiles store raw, tiled elevation data in 0.1m increments. I figured out a very basic working example to generate a mesh using Mapbox's open-source Martini, which is a fast way to generate a terrain mesh. (It looks like you could use @loaders.gl/images instead of get-pixel).

The mesh outputs vertices and triangle indices, and I'm working now to figure out how to integrate that into deck.gl. Is it just:

var Geometry = require('@luma.gl/core').Geometry
var attributes = {
  indices: mesh.triangles,
  positions: mesh.vertices
}
var geometry = new Geometry({attributes: attributes})
const layer = new SimpleMeshLayer({
  id: 'mesh-layer',
  mesh: geometry
});

The SimpleMeshLayer docs say that the attributes object is expected to have positions, normals, and texCoords. Would those be computed from the geometry object?

I'm working on trying to bundle things to test in the browser. I'm still new to JS...

Then I suppose if all of this works out, you could just pass the terrain-rgb tiles to TileLayer, which is apparently able to render custom layers through renderSubLayers.

@chrisgervang
Copy link
Collaborator

I’m nearly done with the implementation of the TerrainLayer. It’s very functional except for a new runtime error that we’re still working out. #3984

@kylebarron
Copy link
Collaborator

I didn't think to check for PRs because it had been a while since you had commented. I'll check/test out your fork!

@chrisgervang
Copy link
Collaborator

Sorry for forgetting to update this thread. I only opened the PR a couple days ago :)

@chrisgervang
Copy link
Collaborator

Btw, I’m not using Martini yet but would love to add that as a geometry option. I’m currently making a basic square grid for the geometry.

If you can see how what you’ve written can fit into the PR, please leave some comments. Thanks!

@kylebarron
Copy link
Collaborator

I think this can be closed now! 🎉

@chrisgervang
Copy link
Collaborator

Hopefully the new layers works well for folks! Fee free to open a new one and cc me if you run into issues.

@kylebarron
Copy link
Collaborator

Additionally, since there's been historical interest in this thread, I wanted to note that I'm working on tools to render deck vector layers clamped to the terrain. I have a preliminary library to snap 2D vector features to the terrain mesh, which works for point and line features.

image

@chrisgervang
Copy link
Collaborator

Wow that looks sooo cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants