escheiermann / low-poly-terrain-generator

A low poly terrain generator for the Unity Engine.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Low Poly Terrain Generator

A low poly terrain generator for the Unity Engine as a editor tool.

editor

Import

To use the terrain generator inside your Unity project, copy the files from the latest release and add them to your project assets

Usage

To use the terrain generator within the Unity Editor, navigate to GameObject > Generate Low Poly Terrain.

editor2

A new window (Wizard) appears on the screen. Parameters to adjust are:

  • Length of the terrain
  • Width of the terrain
  • Maximum Height of the terrain.
  • Material of the terrain.
  • Height Source to shape the terrain according to a pattern.
  • Height Map a grayscale image to retrieve height information (Only usable when Height Source is Height Map).
  • Scale of the noise pattern (Only usable when Height Source is Noise).
  • Tree Density how many trees are placed on top of the terrain.
  • Trees a list of tree Prefabs to be placed on the terrain.
  • Supply Density how many supplies are placed on the terrain.
  • Supplies a list of supply Prefabs (e.g. rocks, etc.) to be placed on the terrain.

How it works

The terrain generator uses the Unity Mesh API to create the terrain.

The Mesh for the terrain is made up with triangles, each consisting of three vertices. The Y-coordinate of each vertex is calculated according to a specific strategy. Currently supported strategies (or Height Sources) are:

  • Random, which calculates a random number between 0 and the Maximum Height using the Unity Random Class.
  • Noise, which uses a 2D Noise Pattern as a Height Source with the Perlin Noise Function from Unity.
  • Height Map, which uses a grayscale image as a Height Source.

terrain

Extending

To extend the Low Poly Terrain Generator and implement more strategies for Height Sources, extend the HeightStrategy Class.

Your own HeightStrategy implementation could look like this:

public class MyNewHeightStrategy : HeightStrategy {
  public MyNewHeightStrategy(int length, int width, int maximumHeight): base(length, width, maximumHeight) {}

  override protected int GetHeight(int x, int y) {
    // Calculate Height...
  }
}

To make your own strategy available to be used from the editor tool, add a new HeightStrategyType to the enum:

public enum HeightStrategyType {
  Random, 
  Noise, 
  HeightMap,
  MyNewStrategy // Add your new strategy type here
}

Also add a new case to the HeightStrategyFactory Class:

public static HeightStrategy Create(TerrainOptions options) {
  HeightStrategy strategy;
  switch (options.heightSource) {
    case HeightStrategyType.MyNewStrategy: // Add your new strategy here
      strategy = new MyNewStrategy(options.length, options.width, options.maximumHeight);
      break;
    case HeightStrategyType.Noise: 
...

License

The terrain generator is licensed under the MIT license. For more information see the project license.

Copyright (c) 2022 Matthias Erdmann & Edgar Scheiermann

About

A low poly terrain generator for the Unity Engine.

License:MIT License


Languages

Language:C# 100.0%