I'm working on some procedural content for Unity3D - in C#
My main aim is to build a flat plane (or maybe later a terrain / mesh), with a single river running through it, based on a seed value.
I will keep the river throughout, but I will have 2 versions of a settlement, one medieval, later one urban city-like.
The over-arching function is basically:
- Input an integer X (scale of settlement) and a seed integer Y
- build a river, maybe roads next if I get the time
- drop x buildings onto the map in a reasonable layout
- once x reaches a pre-defined limit, switch to urban generation
I will probably populate both with generic assets from the asset store or similar, and hopefully will layout the buildings with a decent algorithm.
I've so far been able to generate a reasonably nice Voronoi Diagram using CSDelaunay by PouletFrit
The plan is to maybe treat Voronoi cells as farms for the Medieval time, and then switch form Euclidean Distance formula to Manhattan Distance Formula later for city road generation (but always keeping the same river)
I've converted the 2D code to generate a visual 3D Voronoi Diagram to help me learn the process and how the classes all work.
Examples
2D Voronoi, applied to a Texture2D, dots are 'sites'
3D with graph edge midpoints
I'm struggling with my next step from a planning point of view. In order to build a river through the diagram that looks reasonably well, I might use the method explained in Amit Patel's great procedural tutorial whereby splines are used, from edge midpoint to midpoint. and pick one arbitrary vertex on the north side, one on the south, and perform Dijkstra's algorithm to find the "best" (shortest) path for the river.
I have found a couple of very good spline tutorials such as the one from CatLikeCoding's AMAZING Curves and Splines tut.
but while writing this question I realised I have another option, I can just trace the edge midpoints and the cell 'sites' as in the image below, and increase the polygon (voronoi cell) count to make the river lines seem less angular. it's basic, but should work.
So my main problem now is analysing what to do next.
In theory I could stay working in 2D, build a texture that has rivers and maybe roads, maybe pick more pixel colours for trees, rocks etc, and then instantiate the necessaries into the 3D world. But I'm not sure this is the best approach.
I could instead generate a 3D river using some of the great code explained in "Unite 2015 - A coder's guide to spline-based procedural geometry" and embed it onto a plane or similar, but it's at this point I am getting stuck in analysis paralysis. I can't really decide/determine at a high-level the best way to move forward.
The main questions I am struggling with:
Should I generate a map of some sort in 2D and "extrude" details, or work in 3D from day one ? (main issue here is once I have a list of Vector3 for a river, how do I "apply" it to a plane or terrain ?
Should I use a "shortest path" algorithm for the river (traverse the graph in some way), or generate an independent sine wave with nice looking meanders based on sinuosity as per "Pi me a river"
Should I figure out a way to turn each Voronoi cell into a mesh and/or class so I can explore the relationships between two cells, or is it enough to finally figure out out how the graph data structure is working, and move from there.
I'm not sure how to layout the buildings later.
Why a flat terrain ?
I suppose it might be easier to maintain across the medieval and urban landscapes.
A nice-to-have would be some perlin-noise based terrain, which seems reasonably easy to generate a heightmap and build a terrain from there, but I'm pretty sure I will struggle to get any river algorithm I create to conform to the terrain properly, so I might stick to 2D for the moment.
I need to do this as much in code as possible, and hopefully I can write much of my own code rather than relying on libraries. However I'm not asking for any code help, just some advice to get me out of a rut, if anybody can help I would really appreciate it!
I realise that this sort of question may not be fitting the correct pattern for questions on the site, in which case I apologise, and you can close it off early.
Many thanks in advance.