Skip to content

taKana671/TerracedTerrainModel

Repository files navigation

TerracedTerrainModel

This repository uses the meandering triangles algorithm to create a 3D model of spherical or flat terraced terrain. For spherical terrain, a base sphere is created by repeatedly subdividing each face of the cube into triangles and normalizing the distance from the center to each vertex. For flat terrain, a ground is created by repeatedly dividing a polygon into triangles. And noise such as simplex and cellular is used to calculate the height of each vertex. Then, the meandering triangles algorithm is used to form a staircase-like terrain. The terrain is colored by setting color information directly to the vertices. In addition, by running terraced_terrain_editor.py, you can create a 3D model while checking how the terrain changes depending on the parameters.

Image Image

References

The meandering triangles algorithm is based on below:

Requirements

  • Panda3D 1.10.16
  • numpy 2.2.6
  • Cython 3.2.3
  • opencv-contrib-python 4.12.0.88
  • opencv-python 4.12.0.88

Environment

  • Python 3.13
  • Windows11
  • Ubuntu 24.04.3

Usage

Clone this repository with submodule.

git clone --recursive https://github.com/taKana671/TerracedTerrainModel.git

Build cython code.

If cytnon code is not built, noise is calculated using python code.

cd TerracedTerrainModel
python setup.py build_ext --inplace

If the error like "ModuleNotFoundError: No module named ‘distutils’" occurs, install the setuptools.

pip install setuptools

Code sample

Create an instance of SphericalTerracedTerrain or FlatTerracedTerrain and call the create method to return the panda3D's NodePath of the terrain's 3D model.

from terraced_terrain.spherical_terraced_terrain import SphericalTerracedTerrain

generator = SphericalTerracedTerrain.from_simplex()     # SimplexNoise is specified.
# generator = SphericalTerracedTerrain.from_cellular()  # CellularNoise is specified.
# generator = SphericalTerracedTerrain.from_perlin()    # PerlinNoise is specified.

model = generator.create()

Usage of terraced_terrain_editor.py

Run terraced_terrain_editor.py and select the terrain type(Flat or Sphere), noise and theme. If you want to change the parameters, edit the values in the entry boxes and click the [Reflet Changes] button.

python terraced_terrain_editor.py
Image

Parameters

  • noise: func

    • Function that generates noise.
  • noise_scale: float

    • The smaller this value is, the more sparse the noise becomes.
  • segs_s: int

    • Only for flat terraced terrain.
    • The number of vertices in the polygon that forms the ground; minimum is 3; defalut is 5.
  • radius: float

    • Only for flat terraced terrain.
    • Length from the center of the polygon forming the ground to each vertex; default is 3.
  • terrace_scale: float

    • Only for spherical terraced terrain.
    • Scale of sphere.
  • max_depth: int

    • The number of times that triangles are further divided into triangles.
  • octaves: int

    • The number of times to apply the noise algorithm. Each iteration represent an octave.
  • amplitude: float

    • Noise strength.
  • frequency: float

    • Basic frequency of terrain.
  • persistence: float

    • At the end of each iteration, the amplitude is decreased by multiplying itself by persistence, less than 1.
  • lacunarity: float

    • At the end of each iteration, the frequency is increased by multiplying itself by lacunarity, greater than 1.
  • theme: str

    • one of "mountain", "snow" and "desert".

About

A repository to create a 3D model of spherical or flat terraced terrain

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages