Giter VIP home page Giter VIP logo

low-poly-terrain-generator's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.