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 Support? #110

Open
hecodeit opened this issue Jun 23, 2024 · 4 comments
Open

Terrain Support? #110

hecodeit opened this issue Jun 23, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@hecodeit
Copy link

First of all, thank you very much for this project. It only took an afternoon to get the React Three Fiber and Mapbox project up and running.

Since I am new to this project, I noticed that the map does not include altitude information. Does it support Mapbox's terrain feature: https://docs.mapbox.com/mapbox-gl-js/example/add-terrain/

@hecodeit
Copy link
Author

Already document at: https://visgl.github.io/react-map-gl/examples/terrain

This code can work:

<Map
  antialias
  initialViewState={{
    latitude: 45.646462036649936,
    longitude: 9.598838045131584,
    zoom: 17,
    pitch: 30,
  }}
  mapStyle="mapbox://styles/mapbox/satellite-streets-v12"
  terrain={{ source: "mapbox-dem", exaggeration: 1.5 }}
>
  <Source
    id="mapbox-dem"
    type="raster-dem"
    url="mapbox://mapbox.mapbox-terrain-dem-v1"
    tileSize={512}
    maxzoom={14}
  />
  <Canvas
    latitude={45.646462036649936}
    longitude={9.598838045131584}
    altitude={0}
  >
  </Canvas>
</Map>

@RodrigoHamuy
Copy link
Owner

RodrigoHamuy commented Jun 24, 2024

Hi @hecodeit. I don't think react-three-map should be in charge of deciding how to render your scene based on terrain data, but you can interpret it however you want.

So for a small scene or a fairly flat surface, you can just pass the altitude to Canvas from react-three-map.

For a big scene, you decide how you want to adapt your scene. Maybe by moving the objects position.y or through a vertex shader to change their vertical value based on the elevation data.

But I think it is fair that that's outside of the scope of this project, unless somebody wants to add a component that does exactly this and PR it (😉 😉 ) as an add-on rather than be an integrated part of the current components.

@hecodeit
Copy link
Author

hecodeit commented Jun 25, 2024

Thanks for reply @RodrigoHamuy.

I think the map itself, used as a background canvas. The Three.js part should include position.y information itself. Therefore, the map is flat, or the terrain don't matter. The Three.js scene should including position.y. The connection between them is the data, for map is latitude, longitude, altitude, and for Three.js is xyz information.

For example, a small town has some buildings at lower altitudes and others on hilltops. This town is a Three.js scene. Therefore, the background map will not affect the Three.js scene in any way. However, in this case, displaying the map as terrain is a better choice.

Do you think this understanding is correct?

Screenshot (260)

@RodrigoHamuy
Copy link
Owner

RodrigoHamuy commented Jul 12, 2024

Even if we lift the scene based on the origin coordinates, it will only be at the origin point, so that' won't be enough for most cases. Like in the image you provide, you need to know the altitude at certain intervals and decide if you want to morph the vertices via shader or manually set the geometry correctly. That's why I think this is out of the R3M scope.

@RodrigoHamuy RodrigoHamuy added the enhancement New feature or request label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants