Development Log 7 - Multiple Terrain Handling


Developing Terrain Chunks

This week, work was focused on ensuring that multiple instances of Mesh were displaying tiling around the centre Mesh object.  

Previously, the code for mesh generation were contained within a single script. With the scope of the project expanding, and for modularity, the script was separated out into three distinct elements: 

  • TerrainInformation.cs 

  • TerrainObject.cs 

  • TerrainManager.cs 

TerrainInformation

TerrainInformation class is a non-monobehaviour class, containing the input data required for the generation of a mesh, which maintains a level of abstraction when applying input parameters on creating new meshes. It is serializable which allowed data entry within Unity’s inspector. 

 

Figure 1: The Terrain Information's class and its constructor for passing in new input parameters to its properties.

 

TerrainManager

The TerrainManager script contains a variable of type TerrainInformation titled GlobalTerrainInformation, which stores global terrain information as inputted / generated by the user.  

It also contains a List of all the GameObjects with a TerrainObject / mesh currently generated by the manager. This list and the associated GameObjects containing mesh are cleared and re-generated upon value changes of the Global TerrainInformation

TerrainObject

The TerrainObject script contain their own variable of type TerrainInformation, and these values are passed into it from the TerrainManager’s GlobalTerrainInformation. These represent the local TerrainInformation for that specific mesh instance, which is open to change. 


Tiled Terrain Generation Process 

 

Figure 2: TerrainManager’s method for the generation of local game objects which generate their own meshes via attached TerrainObject scripts.

 

Figure 3: TerrainManager‘s method for generating an array of positional offset data and Perlin offset data for inputting into newly generated TerrainObjects

 

The TerrainManager generates multiple meshes based on the number of tiles determined by the render distance.

The GeneratePositionalOffsets method takes the number of meshes to generate and uses the GlobalTerrainInformation TerrainInformation to calculate the required positional offsets and Perlin offsets to be applied to the generated TerrainObjects. See Figure 3.

Calculating positional and Perlin offsets is essential to ensure cohesion of projected height values across multiple terrain meshes, even when positioned separately.

A loop is completed for each terrain required to generate, with a new GameObject generated with the TerrainObject script attached as a component. The GlobalTerrainInformation TerrainInformation values are then passed into the TerrainObjects own TerrainInformation with adjustments made to the position and Perlin values based on the prior calculated Offsets. See Figure 2.

With the information passed from Global Terrain Manager to local Terrain Object, the TerrainObject script then handles the actual generation of the Mesh. 

 

Figure 4: Current Terrain Output - Tiled meshes

 

The above process accurately allows for the terrain to be spaced out correctly, however an issue appeared regarding the Perlin Offset calculation – it doesn’t accurately calculate the offset to allow for perfect seams, which requires further work.

Future work will also focus on improving the colours displayed by the mesh, working to have height values display different colours and allowing live updating of meshes when values are changed in the Terrain Manager.

Previous
Previous

Development Log 8 - Colour Gradient and Fractal Perlin Noise Implementation

Next
Next

Development Log 6 - Perlin Noise and Implementation