Right now I’m generating a voronoi graph. (I plotted some random points, did a Delaunay Triangulation, then drew edges between the triangle circumcenters and stored them to a list of voronoi cells.)
The whole graph is a series of float values between (0,0) and (1,1). I can render all the edges using debug lines, as seen here:
But I realized I have NO CLUE how to render this to a plane in the world, where I fill in the cell using various terrain textures.
Each voronoi cell has its own array of edges. And each edge is a pair of vectors (a and b).
An example voronoi cell might have the following data (procedurally generated):
e[0].a = (0.4, 0.4); e[0].b = (0.5,
0.45);e[1].a = (0.5, 0.45); e[1].b = (0.48,
0.5);e[2].a = (0.48, 0.5); e[2].b = (0.43,
0.48);e[3].a = (0.43, 0.48); e[3].b = (0.38,
0.44);e[4].a = (0.38, 0.44); e[4].b = (0.4,
0.4);
(e.g.: it’s 5 edges that join up to create a closed polygon.)
I originally created a more grid-based tile map. It was too blocky for my tastes, but was more intuitive to render. I set a two dimensional array of “tile codes” for a grid of 100x100 square tiles. I then used those codes to getpixels/setpixels on a texture2D, one tile at a time. (I then applied that texture2D to a mesh.)
The voronoi diagram isn’t so straightforward.
I can’t figure out how to turn my graph of random floating point values into a texture2D. Since the voronoi polygons aren’t uniform, or even square, I don’t know the best way to fill in the area between the edges with some kind of texture data. I imagine I’d still use getpixels/setpixels? But don’t know how to do it for more irregular shapes, starting from the edge/vector data.
Code would be most helpful. But any advice is appreciated.
