I guess you're using this one: https://github.com/rakai93/godot_voronoi
Looking at the example from https://github.com/JCash/voronoi, looks like you can just iterate through the sites, and then build your polygon from the site's edges.
Here's how he suggests creating triangles (each triangle has a point at the center of the site). You could simply use a bunch of triangles instead of polygons.
void draw_cells(const jcv_diagram* diagram)
{
// If you want to draw triangles, or relax the diagram,
// you can iterate over the sites and get all edges easily
const jcv_site* sites = jcv_diagram_get_sites( diagram );
for( int i = 0; i < diagram->numsites; ++i )
{
const jcv_site* site = &sites[i];
const jcv_graphedge* e = site->edges;
while( e )
{
draw_triangle( site->p, e->pos[0], e->pos[1]);
e = e->next;
}
}
}
Are you sure the edges of a site aren't sorted? I had a look at how he generates his voronoi diagram, but couldn't tell for sure. If they aren't you can sort them yourself like so:
var diagram = generator.generate_diagram()
# Iterate over sites
for site in diagram.sites():
var sorted_edges = get_sorted_edges(site)
# create polygon from sorted edges
function get_sorted_edges(voronoi_site):
var next_edge = site.edges()[0]
var sorted_edges = [next_edge]
var edges_to_sort = site.edges().slice(1, site.edges().size())
while (edges_to_sort.size() > 0):
for edge in edges_to_sort:
if next_edge.end() == edge.start():
next_edge = edge
break
sorted_edges.append(next_edge)
edges_to_sort.erase(next_edge)