Skip to content
Stéphane Malta e Sousa edited this page Sep 12, 2019 · 6 revisions

This guide will help you to import GIS data in Unity and assumes you have FME installed and you're familiar with it (if not, check FME Home licences for free and the online tutorials Safe Software provides).

You can follow this guide with provided sample data or use your own data. There's a shapefile containing the bounding box of the project in datasource\00_perimeter\perimeter.shp. Edit it first to get started with your own data.

Set up Unity

  1. Install Unity
  2. Create a new project from UnityHub
  3. In Hierarchy, create a new 3D Object > Terrain

Terrain

Requirements

In order to create a terrain you'll need:

  • A DEM raster
  • A clean landcover vector file (no holes, no overlaps)

Importing the data

Unity uses a custom RAW raster file heightmap.

  1. Open the workbench located at import/01_terrain/10_GEOTIFF2RAW.fmw
  2. Delete existing 10_terrain.raw and RAWsettings.txt files in the folder
  3. Replace the GEOTIFF **_Reader _**with your own DEM
  4. Edit workbench published parameters:
    1. min_z : the lowest elevation your project could have
    2. max_z : the highest elevation your project could reach
  5. Press play. A 10_terrain.raw raster and a RAWsettings.txt should appear next to your workbench
  6. Open Unity, create a new Terrain game object
  7. Go to the settings of your terrain, under Texture Resolutions section, hit Import Raw... button.
  8. Check Flip Vertically and set the Terrain Size settings with the values found in the RAWsettings.txt file.
  9. Click import. You should see the terrain now.

Texturing

  1. Open the workbench located at import/01_terrain/11_Splatmap.fmw
  2. Delete existing 11_splatmap.png example file
  3. Replace landcover _Reader _ with your own landcover file
  4. Adapt AttributeFilter to your classification attribute and values
  5. Press play. A 11_splatmap.png raster should appear next to your workbench
  6. Go back to Unity, create a folder on Project panel and name it Editor
  7. Copy from this repository unity/Assets/Editor/WorldMachine folder into your Editor folder
  8. Let Unity editor reload, a Terrain menu should appear
  9. In the Hierarchy panel, select your terrain, go to Inpector panel and, click Paint Terrain and select Paint Texture in the dropdown field.
  10. Click on Edit Terrain Layers and add at least 4 layers based on textures.

The order of terrain layers must match the colors on FME script. The order is: Red, Green, Blue, Alpha. If you're using sample data, the order of layers should be: Grass1, Asphalt, Forest, Grass2

  1. Now you've added all 4 layers, select your first layer in Inspector and randomly draw on terrain then File > Save

This will create a splatmap inside the terrain

  1. In the Project panel, click on the arrow to expand your terrain, you'll see an image named SplatAlpha. This is the splatmap to be replaced.
  2. Drag and drop 11_splatmap.png in your Assets folder
  3. Select it and, in the Inspector check Read/Write Enabled and set Format to RGBA 32 bit.
  4. Go to Terrain > Replace Splatmap (from WM)
  5. Drag the splatmap to be replaced to the Splatmap field
  6. Drag 11_splatmap.png to Newsplat field, click Replace
  7. You should see your Terrain textured.
Clone this wiki locally