Build scenes with OpenStreetMap¶
OpenStreetMap allows road networks around the globe to be downloaded as a map file and these files can be imported into Traffic3D to quickly generate scenes at a large scale.
Download an OpenStreetMap file¶
Follow the instructions below to download a map file from OpenStreetMap:
-
Click Here to visit OpenStreetMap.
-
Search the name of the location you wish to model in the textbox.
Alternatively, click and drag the map around until you find a location you like.
-
Zoom into the page using the icons provided by OpenStreetMaps or your middle mouse scroll wheel, to capture the part of the road network you wish to model.
Everything displayed on screen screen will be downloaded into the map file.
OpenStreetMaps has a downloadable limit of 50,000 nodes.
-
To bring up the export UI, select the upper
Export
button. -
To download the map file, select the UI
Export
button.If download failed due to the file exceeding 50,000 nodes, zoom into the page or drag the map around until less roads and buildings are visible.
Import an OpenStreetMap file¶
Follow the instructions below to import a file from OpenStreetMap into Traffic3D:
-
OpenStreetMap files are
.osm
files and must be converted into a text file by renaming the file extension to.txt
. -
Open up Traffic3D in Unity and add your
.txt
file. -
Bring up the GUI to import map data:
Window
>Import OpenStreetMap File
. -
Select your desired map file and the textures/materials to apply to the roads, buildings and floor.
Select the circular buttons on the right to choose your textures.
Note: You will be unable to select
Import OpenStreetMap File
if you are not in a new Unity Scene. -
After a few seconds, your scene will render and the only remaining requirement is to customise the Vehicle Factory.
Information about the Vehicle Factory can be found at Traffic3D Assets.
After modifying the Vehicle Factory the simulation can be run.
Note: It is advised that the top-speed and turning speed of vehicles are reduced to prevent vehicles accelerating too quickly towards corners and driving off the roads.
Modify a road's mesh¶
In the Unity inspector you will find a list of game objects.
A road will consist of a parent object, with two child objects.
-
First Child Object - Contains the road mesh, a
Road Mesh Updater
component and has a child object positioned above the centre node, which displays the road name. -
Second Child Object - Contains a
Path
component and has child objects representing nodes; information about thePath
component can be found at Traffic3D Assets.
After modifying a path, the road's mesh can be quickly updated by selecting the Update Road Mesh
button in the Road Mesh Updater component.
Road Mesh Updater¶
This is used to quickly update a road mesh by only requiring nodes in a Path
to be modified, and will automatically modify the mesh when the Update Road Mesh
button is selected.
The script has the following fields:
- Road - The game object the script is attached too, which should also contain the
Mesh Renderer
andMesh Filter
components. - Path Object - A game object with the Path component attached, and shares the same parent object as
Road
. - Num Lanes - The number of lanes in the road.
- Lane Width - The width of each lane in meters.
- Update Road Mesh - A button which will change the shape of the mesh in the
Road
field to match the shape of the path in thePath Object
field.
Limitations¶
The current version of the import system has some restrictions on the types of networks which can be modelled:
-
Only grid systems, such as those found in American cities, can currently be modelled as the system only supports cross junctions.
-
Variations in road heights, such as tunnels and bridges, are not supported and as all roads will be generated at the same Y-level.