The purpose of this project is to illustrate the workflow of exporting vector data representing Earth's countries from the R package rworldmap, generate C# classes that can be used in Unity3D, and finally visualize the data in Unity3D accordingly as extruded polygons (prisms).
- R script required to access and generate all
Vector2
country data from the rworldmap package. - Generation of C# classes that implement the provided
IRWMMeshData.cs
interface. - Unity3D script to visualize all country data as individual
GameObjects
, integrated using Unity - PolyExtruder. - comprehensive documentation across all source files
This project has been built using the following specifications:
- Unity3D 2020.2.1f1 Personal
- Unity - PolyExtruder (cloned on 2021-02-02)
- R 4.0.3
- RStudio 1.4.1103 (OS X)
- rworldmap (accessed on 2021-02-02)
Please note that the compiled data from the rworldmap is not included in this repository. Please follow the instructions below to access and compile yourself the data for own use.
All source code can be found within the r_src
directory of this repository. Carefully investigate the rworldmap_export_to_unity.R
file to follow the implementation.
- Copy the
rworldmap_export_to_unity.R
file into your R default working directory. - Inside your R default working directory, create a new directory with the name
rworldmap-unity-files
. - Open RStudio, and open the
rworldmap_export_to_unity.R
file. - Ensure that you have the rworldmap package installed. Potentially, run
install.packages("rworldmap")
. - Run all contents of the
rworldmap_export_to_unity.R
. - All C# mesh data files will be generated and placed into your
rworldmap-unity-files
directory (see step 2). - Additionally to the mesh data files, you will find a file named
_init.cs
containing the C# initialization code snippet (to be later copied into theWorldGenerator.cs
script; see further Unity3D related steps below).
All source code can be found within the unity_src
directory of this repository. Carefully investigate the WorldGenerator.cs
file to follow the implementation.
- Create a new Unity3D 3D project.
- Import the Unity - PolyExtruder package to your project.
- Import the
WorldGenerator.cs
andIRWMMeshData.cs
scripts to your project. - In your Unity scene, create a new empty GameObject (make sure its properties are
reset
), and attach the importedWorldGenerator.cs
script as a component. - Import all generated mesh data files from your
rworldmap-unity-files
directory to your project (except for the_init.cs
script). - Open the
WorldGenerator.cs
script, and copy all contents of the_init.cs
script to the marked location inside theAwake()
function. - Run your Unity3D application. All created country GameObjects are attached as Child GameObjects to the GameObject that has the
WorldGenerator.cs
as a component attached (see step 4). - For further configuration of the extruded country polygons, please refer to the Unity - PolyExtruder documentation.
MIT License, see LICENSE.md