Skip to content

Unreal Engine 4 scripts to: prepare and tile from SRTM (and others) DEM to UE heightmaps keeping real world dimensions and proportions. Create landscape materials. Assign landscape materials to tiles among other tools.

License

Notifications You must be signed in to change notification settings

Rodrigo-NH/UE4HmapsGenerator

Repository files navigation

UE4HmapsGenerator (heightmaps generator)

Unreal Engine 4 scripts to:

  • Prepare and tile from SRTM (and others) DEM to UE heightmaps while keeping real world X,Y,Z proportions and metrics (UE u.u.) (>srtm2heightmap.py<)
  • Create landscape textures and materials. (>materialsgen.py<)
  • Assign landscape materials to tiles. (>applymaterials.py<)
  • Import line features from shapefile. (>importlines.py<)

Output example: https://www.youtube.com/watch?v=91U2XWXpHJk

>srtm2heightmap.py<

Script that takes GeoTiff (and other GDAL valid file drivers, SRTM .hgt images e.g.) and generates UE4 hightmaps tiles and texture files. Script needs GDAL installed (No need to have GDAL python binds installed). On Windows the easiest way to install GDAL is osgeo4w Also on Windows make sure you have appropriated sys environment sets, e.g.:

  • "GDAL_DATA C:\Program Files\GDAL\gdal-data"
  • "GDAL_DRIVER_PATH C:\Program Files\GDAL\gdalplugins"
  • "GDAL_VERSION 3.1.1"

Script will ask for all necessary parameters needed to take the input images, generate the tiles and generate/inform the necessary importing X,Y,Z UE4 scales. It will generate a 'customtiles' directory and auxiliary files in the same directory as origin files are located. The image file to be used as landscape texture/materials is optional but if you use it, needs to be a georeferenced file as well in the same projection/EPSG as the DEM file. Look the code for the 'METER_BY_DEGREE_FACTOR' variable, adjust as necessary depending the part of the globe you're working. This conversion is necessary if we need convert spatial resolution (pixel size) in decimal degrees to a metric reference (meter) as UE4 workspace is a orthogonal world. It may be better using a DEM image already in a ortoghonal projection (e.g. UTM) as you don't need to adjust 'METER_BY_DEGREE_FACTOR', accordingly your final objectives. This script was tested with SRTM DEMs but will accept other valid GeoTiff images. Starting from raw SRTM images if you don't know how to answer the Y/N questions, answer (Y)es for all of them to get started. How to download SRTM

The conventions used by the script are the following:

Scene origin

The script will detect the most top left coordinates as the origin coordinates for the tiles extraction. Script will ask if user wants to use the detected origin coordinates or indicate alternative coordinates somewhere in the scene to be used as origin for tiles extraction.

UE import screen

You can use the script to produce a single tile and import directly in landscape mode. If importing tiles in world composition mode, make sure option 'Flip Tile Y Coordinate' is not selected. Either way, use the X,Y,Z scales calculated by the script in the importing screen. Take care to not select texture 'texture_' files but only the heightmaps png files;

>materialsgen.py<

This script will import the texture files, create and set the materials to be used for each tile. Copy this script under your UE project '/content' folder, edit and change the 'inputdir' and 'UE4_TILE_TEXTURE_SCALE' variables accordingly and run in the UE4 project instance (e.g. File->Execute Python Script). After importing all textures the resulting blueprint for each tile material will be like:

UE blueprint

>applymaterials.py<

This script simply apply the texture materials in the corresponding tiles/levels. Take note that for this to work the levels/tiles must be loaded in the viewport/project. This way you can load textures in parts or the whole thing at once.

>importlines.py<

This script will import lines from a given shapefile. Intended to be used with orthogonal origin workspace (UTM e.g.). It will read (optional) elevation/height from line features. 'Snap to ground' and 'Render mesh' functionality in the accompanying Blueprint. This script needs gdal python bindings installed.

  • Copy ImportLines bluerpint from blueprints directory to UE project's folder
  • Copy the script inside your project (content folder)
  • Edit the script to set the necessary references. You will need information generated by >srtm2heightmap.py< like X,Y Origin. Also edit the path of your installed gdal python bindings.
  • Run the script from UE project instance to import the lines.
  • After importing you can use blueprint's 'SnapToGround' function to snap splines points to ground (and other surfaces in it's vertical range) and use 'RenderMesh' to render a selected mesh along the splines. You can select all the lines in World Outliner and snap to ground or render mesh in one go.
  • You need to set the mesh to be rendered in the blueprint. importlinemesh
  • You can set a 'Z offset' for the splines in the blueprint importlineoffset importlineoffsetexample Example lines with a Z offset

About

Unreal Engine 4 scripts to: prepare and tile from SRTM (and others) DEM to UE heightmaps keeping real world dimensions and proportions. Create landscape materials. Assign landscape materials to tiles among other tools.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages