Hey!
The last few weeks I was busy working with the procedural generation of a planet (which consists *mostly *of hexagon tiles - more on that in a sec)!
I have seen a lot of map generators that inspired me (for example Zeustiak’s Map Generator). Nevertheless I wanted to work on a generator that created planets instead of 2D maps.
Any comments, ideas or answers to my several problems would be vastly appreciated.
Here is where I am now (this is biome view btw. I have a temperature, elevation and humidity view too - you can also view the wind in the form of arrows) :
Another one with around 10k tiles: (Arrows are for winds)
Summary:
A Planet Generation algorithm that begins by creating a procedural mesh, split into hundreds of tiles. Then **elevation **is calculated using tectonic plates - and continents are formed. **Heat **and **humidity **come next as well as some **wind **patterns. Finally using the previous calculations I assign **biomes **to titles.
A quick tour:
- Procedural mesh generation: Starting with a regular icosahedron, I subdivide it as much as I want to (for the above size it’s 4 subdivisions - my PC can handle up to 5 or 6 but it is noticeably slower). Then I generate the dual polyhedron to create a sphere that consists of hexagons and some pentagons.
- Tectonic Plates and Elevation: After creating my sphere, I create tectonic plates (around 50 of them) by selecting random (non-neighbor) tiles and using voronoi as well as just a tiny bit of randomness. Each tectonic plate is set as an oceanic or not and a velocity around the center of the planet. Then after calculating pressure in the borders (and depending on how the plates collide)I generate the elevation and spread it inwards.
- **Winds **are for the moment randomly generated. I start by assigning huge winds around locations and then bluring and adding up those winds for nice patterns. I actually don’t like the fact that the winds are before the heat mechanism (wind should actually go from warm to cold locations).
- Temperature: Each tile receives heat from the sun. Locations near the equator receive more heat than ones further away. Then this heat is spread around using winds. If heat is concentrated too much in a tile then heat radiates back into space. Unfortunately due to the randomness of the winds I had to tweak stuff a lot to keep ice in the poles and tiles near the equator warm.
- Humidity and precipitation: Humidity (as mass of water /cubic meter) is generated in the oceans then spread around using the wind. If relative humidity is very high in a tile (relative humidity is affected by absolute humidity and temperatures) then it becomes rain.
- Biomes: Finally I generate a biome for each tile depending on their temperature, elevation and precipitation. No real difficulty here, I just google’d up biomes and using my understanding I assigned a range of values there.
Future Plans
- Rework heat and wind patterns - since those two should be connected
- Add resources to my generat
- Figure a solution for the pentagon tiles. I am thinking about adding several pentagons and heptagons to break the symmetry. Nevertheless I am a bit lazy to work on that now…
- I am not happy about the precipitation. I feel that random tiles are getting a lot of rain while tiles right next to them are deserts.
- Finally I want to add navigation & stuff like that to my planet so that simple units can move around. In a few words create a framework for my future strategy game.
Let’s get started:
Procedural Mesh Generation
This actually took most of my time. The first and simple idea was to start with a simple icosahedron and *subdivide *it as much as I had to, to create my initial sphere.
While at that time it looked like a simple idea I had no idea how to start creating my mesh. I went ahead and made a simple icosahedron using the custom mesh component by hard coding the vertex coordinates and the edges (that’s actually a valid way to create an icosahedron).
Nevertheless when I went ahead to split the edges I hit a wall. There was no obvious to me way to keep track of which edge I was splitting - and even when I found a solution to this I was always losing track of neighbor faces. The way I was representing my mesh was too simple to support any complex operations like subdivision. This got me reading a lot of papers on mesh representation (I was totally clueless before this) until I decided I was going with the half edge data structure also known as double connected edge list.
After coding the whole data structure and re-creating the icosahedron using it, I was able to proceed to subdividing it. By this time I had moved to using the Procedural Mesh Component.
The second part of the problem now, was to create hexagon tiles from this subdivided icosahedron. The idea again was simple: Treat each vertex as a *future *face (or tile), and the centroid of each neighboring triangle as the corner of those future faces:
(excuse my painting skills - I did my best)
As you can understand, the black triangles are the old faces of the subdivided icosahedron and the red ones are the generated hexagon tiles. By the way this is called a dual polyhedron
Of course that wasn’t so easy as I hoped it to be, because I was losing neighboring tiles all the time. It wasn’t that hard either though.
The problem that arose was that you can NOT have a sphere out of hexagons - more about this here.
You **always **end up with pentagons in the places of the original icosahedron vertices. That was something I actually knew from the beginning - this irregularity is why I chose to start with a procedural mesh and not by slamming hexagons in an instanced mesh.
Anyway, the results were not bad at all:
(The screenshot was from when I was experimenting with materials, that’s why I had to paint it over with black lines, for you to see. The red are the pentagons)
The first part, the mesh, was done. I had some ideas to break the symmetry created by the pentagons by adding more pentagons in random locations. (Actually that idea was from a similar generator I had seen somewhere but can’t find anymore to link )
I will follow right away with tectonics (elevation), temperatures, winds & more!