-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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.
- Install Unity
- Create a new project from UnityHub
- In Hierarchy, create a new 3D Object > Terrain
In order to create a terrain you'll need:
- A DEM raster
- A clean landcover vector file (no holes, no overlaps)
Unity uses a custom RAW raster file heightmap.
- Open the workbench located at
import/01_terrain/10_GEOTIFF2RAW.fmw
- Delete existing
10_terrain.raw
andRAWsettings.txt
files in the folder - Replace the GEOTIFF **_Reader _**with your own DEM
- Edit workbench published parameters:
-
min_z
: the lowest elevation your project could have -
max_z
: the highest elevation your project could reach
-
- Press play. A
10_terrain.raw
raster and aRAWsettings.txt
should appear next to your workbench - Open Unity, create a new Terrain game object
- Go to the settings of your terrain, under Texture Resolutions section, hit Import Raw... button.
- Check Flip Vertically and set the Terrain Size settings with the values found in the
RAWsettings.txt
file. - Click import. You should see the terrain now.
- Open the workbench located at
import/01_terrain/11_Splatmap.fmw
- Delete existing
11_splatmap.png
example file - Replace landcover _Reader _ with your own landcover file
- Adapt AttributeFilter to your classification attribute and values
- Press play. A
11_splatmap.png
raster should appear next to your workbench - Go back to Unity, create a folder on Project panel and name it
Editor
- Copy from this repository
unity/Assets/Editor/WorldMachine
folder into yourEditor
folder - Let Unity editor reload, a Terrain menu should appear
- In the Hierarchy panel, select your terrain, go to Inpector panel and, click Paint Terrain and select Paint Texture in the dropdown field.
- 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
- 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
- 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. - Drag and drop
11_splatmap.png
in your Assets folder - Select it and, in the Inspector check Read/Write Enabled and set Format to RGBA 32 bit.
- Go to Terrain > Replace Splatmap (from WM)
- Drag the splatmap to be replaced to the Splatmap field
- Drag
11_splatmap.png
to Newsplat field, click Replace - You should see your Terrain textured.
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.
- Open the workbench located at
import/02_buildings/00_SHPtoOBJ.fmw
- Replace the SHAPEFILE Reader with your own 3D polygons
- Edit destination path, create a new folder inside your Unity Assets folder and name it
Models
- Press play. 3DS files should appear in Models folder
- 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.
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.