Closed blacksmith94 closed 2 years ago
A lot of this project is about the rendering, so those parts wouldn't show up on a tile map. You can preview what the tile map would look like by changing these settings:
flat
to 100%ambient
to 0%overhead
to 100%mountain_height
to 0%outline_depth
to 0%outline_water
to 0%You might even be able to use that image to turn it into a tile map. Alternatively, look at mapgen2 with icons turned off to get a similar map.
Mapgen4 code is ugly in part because it's trying to support the real-time updating of the map as you draw.
The underlying data is a polygon mesh, using voronoi+delaunay. I have a tutorial that explains how this works. From there, you can rasterize triangles into pixels, and treat those pixels as tiles. Mapgen2 and mapgen4 both rasterize to color images, but for tile data you'll probably want elevation grayscale (0–255) and moisture (0–255) so you can convert those into biomes. In mapgen4, the data is stored in a_em
{x: elevation, y: moisture}, and these points are sampled at a_xy
{x: x position from 0–1000, y: y position from 0–1000}. You'll have to render these vertices as triangles (GL_TRIANGLE).
If you want to start with simpler code instead of trying to figure out the ugly mapgen4 code, this page starts with simpler code for generating the elevation and moisture, and it works directly with tile maps and doesn't need the voronoi+delaunay parts at all. In my own projects, when all I want is a tile map, I start with this page instead of mapgen4.
Thank you for your answer. I already made some tilemaps with Perlin Noise, but i wanted to try your project using voronoi cells for rivers and lakes. It really is a great project, I managed to extract all the "Map" object to a json, but i couldn't understand the generated data.
My goal is to obtain an array of objects with a structure like this (or similar):
{
type: "fresh water" | "salt water" | "land"
X : 0,
Y : 0,
elevation: (range from 0 to 1),
moisture: (range from 0 to 1)
}
I'll give it a try with the tips you just told me.
I'll close this thread myself if i don't run into any other issues. Thank you again.
EDIT:
By looking at the map json, i understand that inside the map object, the values of the dictionaries t_elevation
and t_moisture
correspond to each triangle's value, since the length of the dictionaries match mesh.numTriangles
I have a few questions:
let polygons = [];
for (let r = 0; r < map.mesh.numSolidRegions; r++) {
polygons.push({
biome: map.r_biome[r],
vertices: map.mesh.r_circulate_t([], r)
.map((t) => map.t_pos([], t))
});
}
My plan is to load this json into a C# object and do the rasterization there. But i don't understand how each of the parameters relate to each other. I've read your articles but you don't mention most of this parameters in the map object.
Ah, yes, mapgen4 is far more complicated than mapgen2 because of the interactive drawing and the rendering. :-( If you load the mapgen2 page and the mapgen4 page you'll see that the island shapes are fairly similar for the same seed, but making the interactive drawing and the 3d rendering required a lot of hacks, which messed up the code. One of these days I'll want to go back through and undo the hacks and make a clean version of mapgen4! :-)
The naming convention is that r
is for a region number and t
is for a triangle number. These two are related in the Voronoi-Delaunay dual mesh: each delaunay triangle t will be made out of three r points as vertices, and each voronoi region r will be made out of many t points as vertices. See diagrams on https://mapbox.github.io/delaunator/
"How do I know the vertices of each triangle?" → To get the vertices of a triangle, the mesh object has some methods: mesh.t_circulate_r(output_array, t)
will find delaunay triangle t and write its r values into the output array. Similarly, mesh.r_circulate_t(output_array, r)
will find voronoi region r and write its t values into the output array. There are six methods like this, named FROM_circulate_TO.
"How do i get the vertices of the noisy edges?" → mapgen2 has noisy edges but mapgen4 does not. I like how noisy edges look, but I only got them working in 2d rendering in mapgen2 and not in 3d rendering for mapgen4, so mapgen4 doesn't have them. In mapgen2, they're in the noisy-edges.js file. Read more about it here.
"*Is it possible to obtain the same information in polygons? Like the examples you gave in mapgen2?" → You can get the vertices for the polygons the same way, since it's the same mesh class I use in both projects. Mapgen2 uses discrete biomes like "desert" and "forest" but mapgen4 doesn't. There is no r_biome[]
array in mapgen4 but you can look at r_elevation[]
and r_rainfall[]
and assign a biome to regions, or you can use t_elevation[]
and t_moisture[]
and assign a biome to triangles. I have an example biome assignment function here.
Happy to answer more questions!
How do I translate the generated map to a tilemap?
I want to store all the information in a matrix, any approach on how would you do this?