delebash/unreal_mapbox_bridge

Great work on this!

colkassad opened this issue · 8 comments

You had asked me a question about me accepting pull requests on my repo, but I think you should just continue with what you have here. If I have some time I'd love to contribute to this repo going forward. I love what you have done! I think leaning into the Unreal Engine workflow is a great choice. If you ever want to reach out, my email is my github username at gmail.

Thanks. I am currently trying to take the geojson coordinates of features for the selected tile and draw them on an Unreal Engine landscape. The problem I am having is getting the lon/lat coordinates to match up with the imported heightmap. I am using the new 4.27 Georeferencing system. I am stuck trying to convert the coordinates correctly. If you have time, I could use the help figuring this out. Here is my question on stackoverflow that describes what I am trying to do. https://stackoverflow.com/questions/70582519/how-do-you-convert-long-lat-coordinates-for-a-selected-feature-in-mapbox-tile-ge. My current thought process is to get the lon/lat at the center of the bounding box and use that as a reference starting point for the Georeferencing system. I can get the long/lat center of the bbox no problem but even using that as a starting point in Unreal I still can't get the coordinates of the geojson features to match. I will upload these changes soon so you can try it out if you want. https://terrain.justgeektechs.com/#/. TY! and Cheers!

I took a look at the Unreal Engine Georeferencing docs...lots to take in there. I'm a geospatial developer and I've never used ECEF coordinates...my guess is you are seeing a non-zero elevation in your conversion as that might be the distance from the center of the earth. However, even with that your coordinate that is returned in your SO question seems wonky. Have you considered using a Projected CRS in Unreal and projecting your lat/longs to UTM and using the Flat planet shape option? Given a lat/long, you can determine the UTM zone's EPSG number with this formula (in Python):

def get_utm_epsg(lon, lat):
    """
    
    Returns the EPSG number for a UTM zone from a given
    input longitude and latitude.

    Parameters
    ----------
    lon : Float
        Longitude.
    lat : Float
        Latitude.

    Returns
    -------
    epsg : Integer
        The EPSG number for the UTM zone for the input longitude
        and latitude.

    """
    offset = int(round((183 + lon) / 6, 0))
    epsg = 0
    if lat > 0:
        epsg = 32600 + offset
    else:
        epsg = 32700 + offset
    return epsg

Also, your blueprint wasn't showing up at that website, it just redirects to the home page. Do you need to set it to public or something?

Here is the repo to the Unreal Plugin https://github.com/delebash/UnrealMapboxPlugin. You should be able to download it and open in UE4.27. I am not sure how familiar you are with UE but you will need to show plugin and engine content. Then scroll down to UnrealMapboxPlugin Content then choose the blueprint folder and right click and run the editor widget. You can also edit it to see the current blueprint. Also here is the link for the web version and yes it was set to private :(. https://blueprintue.com/blueprint/-zo2hsac/. I can produce projected coordinates from Mapbox in WGS84 EPSG:3857. I tried this but it still does not look right.

Cool, I'll try to load your plugin as soon as I can. I imagine EPSG:3857 can give you problems, especially as you get further north. Maybe try on a tile on the equator and see if you get better results. I read the Unreal docs in more detail....maybe try this:

Assumptions: Your heightmap is centered on (0, 0, 0) in the level and you know the lat/long of the center of the heightmap

In the GeoReferencingSystem:

  • Planet Shape: Flat Planet
  • Projected CRS: EPSG: XXXXX (from the google search / code provided above)
  • Geographic CRS: EPSG: 4326
  • Origin Location in Projected CRS: unchecked
  • Origin Latitude: latitude of center of heightmap
  • Origin Longitude: longitude of center of heightmap
  • Origin Altitude: 0

Then for your blueprints, get a reference to your GeoReferencingSystem and for each coordinate in your GeoJSON, pipe it through Geographic to Projected --> Projected to Engine. To obtain the z value (like if a road is going over a mountain), you will need a method to query the heightmap to obtain that "pixel value". Or maybe Unreal provides a method to query the level heightmap at a specific X, Y to get a Z?

Other things to consider:

  • Entities that cross UTM zones. I assume in this case you would need to do a UTM zone check for each coordinate and generate/update a GeoReferencingSystem object before doing the conversion.
  • Autogenerating tiles in your level. If you are doing this, it may be easier to set your origin starting tile to have its origin at (min_x, min_y, 0). However, I think Unreal has a way of resetting the origin or something for larger levels and you may already be aware of this.

Awesome, I will give it a try. When you generate the tile image from the web app it will create a geojson file with features and coordinates. For testing I have a file with just a single road in it to make things easier. The test files are located in UnrealMapboxPlugin\Plugins\UnrealMapboxBridge\Resources\Test Geojson Files\wewahootee road Florida. When you run the widget just click on the button and load the sample geojson file. The tile_info.json file has the center of the bounding box, I hope. From what I could figure out from Mapbox it should be.

"bbox_center": {
"lng": -81.10536575317383,
"lat": 28.422353711415433
},

Thanks for the help and you are more than welcome to contribute to the projects. It would be great working on these together.

Hmm, just noticed this in the docs: "For floating point accuracy reasons, these origin values have to be integers to avoid bad roundings." A single degree in WGS84 is huge so Origin Location in Projected CRS should be checked and you should know the center coordinate in UTM meters. Not too difficult.

Cool, I'll try to recreate with your test data once I get your plugin loaded.

I also have a problem with the generated heightmap. When you import the heightmap the landscape is not created at sea level. Please see #7

Please try downloading the UnrealMapboxPlugin https://github.com/delebash/UnrealMapboxPlugin. It should work now. There was an extra dependency that was not needed. Let me know if you have any problems. Also, if we could move discussions for UnrealMapboxPlugin to https://github.com/delebash/UnrealMapboxPlugin/issues/

Thanks.