For some time I wanted to create a script that could erode meshes to complement landscape add-ons like ANT.
The first step is presented here:
erode.py, a python script that simulates thermal erosion, i.e. the landslides on steep hill slopes and the gradual breaking up of large boulders by freeze/thaw processes (called diffusion in the code).
It's currently a stand alone script and not yet a proper Blender add-on but it does read and produce raw mesh data that can be exported/imported in Blender (by the raw input/output bundled add-on). It can read hand crafted heightmaps but it is also possible to create some artificial shapes. In its current form the script is intended to verify the algorithms used and get a feel for the simulation parameters.
Code availability and dependencies
The script is available on GitHub. It needs Python 3.2 or newer and depends heavily on NumPy. The code is even multithreaded when the NumExpr package is installed as well and this can make a huge difference for larger grids.
Some examples are shown below. The first mesh is a mesh generated with ANT. In the second one we applied a few iterations of just the landslide algorithm, which removes the steepest slopes and in the final example we also applied diffusion, softening the landscape as a whole.
The script isn't very user friendly at the moment but does have a fair number of options:
usage: erode.py [-h] [-I ITERATIONS] [-Kd KD] [-Kh KH] [-Kp KP] [-ri] [-ro]
[-i] [-t] [-infile INFILE] [-outfile OUTFILE] [-Gn GRIDSIZE]
[-Gp GRIDPEAK] [-Gs GRIDSHELF] [-Gm GRIDMESA] [-Gr GRIDRANDOM]
[-m THREADS] [-u] [-a] [-n]
Erode a terrain while assuming zero boundary conditions.
-h, --help show this help message and exit
-I ITERATIONS the number of iterations
-Kd KD Diffusion constant
-Kh KH Maximum stable cliff height
-Kp KP Avalanche probability for unstable cliffs
-ri use Blender raw format for input
-ro use Blender raw format for output
-i use an inputfile (instead of just a synthesized grid)
-infile INFILE input filename
-outfile OUTFILE output filename
-t do not write anything to an output file
-Gn GRIDSIZE Gridsize (always square)
-Gp GRIDPEAK Add peak with given height
-Gs GRIDSHELF Add shelf with given height
-Gm GRIDMESA Add mesa with given height
-Gr GRIDRANDOM Add random values between 0 and given value
-m THREADS number of threads to use
-u perfom unittests
-a show some statistics of input and output meshes
-n use numexpr optimizations
Exporting and using an ANT generated mesh
- Create a landscape mesh
- For example with ANT but of course you can sculpt one as well or import a DEM
- Export the mesh
- File->Export->Raw. Make sure you enabled the add-on
- Erode it
- See example commandline below
- Import the mesh
Assuming you exported the grid to a file called
untitled.raw, you could erode that file and put the result in a file called
out.raw using the following command line:
python erode.py -Kd 0.001 -Kh 0.03 -i -infile untitled.raw -ri -outfile out.raw -ro -I 10
(Which model parameters (especially Kh) to use depends of course on the input mesh.)
Erosion due to whethering isn't all that interesting in itself but serves to test the basic data structures in the script. Water erosion is the final goal so the roadmap for this script is short: fluvial erosion (creation of canyons and gullies and the deposition of sediment due to rain) will be next and when that works I'll rework the script to a proper addon. After that we'll see if there is demand for other features. I would like to add meandering but based on my current research I think that's quite some effort so I'll see if I can find the time.