Skip to content
Stéphane Malta e Sousa edited this page Feb 26, 2020 · 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 2D 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.

Buildings

Requirements

The FME script preparing the buildings for Unity are meant to load a LOD2 CityGML building dataset or similar. You'll need at least:

  • Ground surface
  • Walls
  • Roof

If you already have a clean and textured dataset, it's better not use FME to import it. Just translate your coordinates to Unity coordinates.

Importing the data

  1. Open the workbench located at import/02_buildings/00_SHPtoOBJ.fmw
  2. Replace the SHAPEFILE Reader with your own 3D polygons
  3. Edit destination path, create a new folder inside your Unity Assets folder and name it Models
  4. Press play. 3DS files should appear in Models folder
  5. In Unity, drag buildings from Project panel and drop them in Hierarchy panel. Don't drop them in the Scene directly. Dropping things in Scene require their transform to be reset if you want to control position with original coordinates.

TreeInstances

You can import trees, streetlights or any vertical prefab of your choice as a TreeInstance on Terrain. To do so, two FME scripts are provided:

  • import/03_trees/00_Trees2JSON.fmw
  • import/04_streetlights/00_StreetLights2JSON.fmw

There are not common models handling trees so adapt these scripts to your needs. Check carefully the resulting JSON provided here:

  • unity/Assets/Editor/trees.json
  • unity/Assets/Editor/streetlights.json

Your JSON should look like that. Take care, coordinates are relative to Terrain: their values go from 0 to 1

When your JSON is ready copy the unity/Assets/Editor/TreeImporter.cs into your Assets/Editor folder, a menu SITN should appear allowing trees to be imported.

Clone this wiki locally