Terrain Generation System
This project is a Procedural Generation System designed specifically for terrain generation. Utilizing fractal noise, the system dynamically generates binary mesh data files for terrain based on the parameters provided, eliminating the need for manual crafting. This system significantly reduces development time while enhancing replayability.
​
Function Overview:
- The user creates a JSON file declaring the parameters.
- The console application outputs binary mesh data.
- The game reads the mesh data and render the terrain.





Parameters explanation:
Explanation of parameters except "thresholds" and "colors" can be found at Update #2.
* thresholds & colors:
n threshold values separate the height range into n+1 divisions.
Vertices with height in i-th division will have the color of color[i].
​
Example of different parameters:
Larger scale and gain give more frequent and drastic change in terrain.


Smaller scale and gain give smoother change in terrain.


How I used what I learned this semester:
- Make the generator which takes JSON files as input and outputs binary mesh data as a console app, and use lua scripts to run it.
- Build mesh data into binary files correctly at build time, and parse the binary data correctly at runtime.
- Build mesh data with vertices and indices as triangled-based data, which can be processed by D3D and OpenGL.
- Submit data from the game projct to the graphics project.
​
Difficulties:
The greatest difficulty I encountered is to accomodate the indices limit of a single mesh file. The terrain can have a large number of vertices, but a single mesh file can only hold 2^16 indices at most. The details and my solution can be found at Update #2.
​
Download:
The zip contains directories/items below:
- ProceduralMeshBuilder_App (x86 and x64 versions)
This application builds JSON to binary mesh files.
- ​JSON_Lib (x86 and x64 versions)
Built from nlohmann/json which parses json objects.
- ​ProceduralMeshLoader_Lib (x86 and x64 versions)
This library parses the binary mesh data. This library depends on Graphics_Lib.
The way of how the binary data is parsed differs with different mesh representations.
- ​[Optional]Graphics_Lib (x86 and x64 versions)
This library gives my representation of mesh and the way I parse binary files.
A small modification I made to Graphics is to not update static meshes every frame, which can be found at Update #1. This modification is optional and does not relate to PGS.
- AssetBuildFunctions.lua
The lua script to run the application.
- SampleTerrain.json
A sample of PGS JSON file.
- raw
Raw codes of all things above.
- [Optional]Graphics
- Grapics: The small modification mentioned above.
- cMesh: My representation of mesh and my way to parse binary files
- ProceduralGenSys
Codes for ​ProceduralMeshLoader_Lib.
- ProceduralMeshBuilder
Codes for ProceduralMeshBuilder_App.
- MyGame
A sample of how to use all things above in the game.
Instructions & Suggestions:
1. Copy items in ProceduralMeshBuilder_App to the output folder of your game build (temp/Platform/Configuration/output), or add the raw codes of ProceduralMeshBuilder of as a project to your solution.
2. Copy items in JSON_Lib to the output folder of your game build if you don't have it yet (temp/Platform/Configuration/output), or add the raw codes which can be downloaded from nlohmann/json
3. Create your JSON file for terrain generation, following the sample.
4. Add the lua codes to run the application (AssetBuildFunctions.lua)

5. Add the JSON file you just created to AssetsToBuild.lua

6. Build your solution, you should be able to see the generated binary mesh files in the output folder.
7. Now you need to figure out how to read the binary files. In theory, you can just import the library, but it highly depends on how you represent and parse mesh data. So I highly suggest you add the raw codes ProceduralGenSys as a project to your solution, and relate it to your cMesh::Load(). Then, you can look at the raw codes I provided for cMesh and modify the codes in your solution.
The way I parse my binary mesh data is shown below:

8. If you managed to parse the binary mesh data, it should be good to go!
Contact:
If you have any questions about the project or you need more instructions, feel free to contact me at junxuan.hu678@gmail.com.
​