Demonstration.mp4
Procedural City-Generation Project.
This project is a sub-project of the FindingYonghee project.
FindingYonghee
project has further implemented a Crowd Simulation based on Reinforcement Learning.- This project only handles City-Generation.
- Every City-Generating Code is at CityGenerator.cs file.
- You can download executable file from Release.
[Warning] Because this project was developed with paid assets (3D models, toolkits), we intentionally did not upload them to this repository, so even if you download those assets and run the project, it may not work properly. If you want to test this project, please use released executable file.
Dependencies
-
Included
-
Not Included
Reference Paper
Citygen: An Interactive System for Procedural City Generation
- Generate Initial Point & Voronoi Diagram
- Set Boundary of Voronoi as Primary Road
- Group Voronoi as City Cell & Set City Cell Boundary as Primary Road
- Generate Secondary Road & Graph
- Generate Primary Road Spline
- Generate Secondary Road Spline
- Reposition Connector
- Generate Primary Buildings
- Generate Secondary Buildings
-
Generate initial points with an appropriate distribution using
Poisson disk sampling
and use them to create a Voronoi diagram. -
Afther that, use
Lloyd's Algorithm
to relax Voronoi Diagram with specified iteration count.
-
Set the outermost edges of the Voronoi Diagram as the
Primary Road
. -
Primary Road
is a wide road, from which theSecondary Road
, a narrower road, branches off.
-
First, find a bounding rectangle that contains all of the sites in the previously created Voronoi Diagram, and make it 3 times the distance between the centers of each site compared to original Voronoi Diagram, so that each site is larger.
-
This will result in two Voronoi Diagrams, grouping all the
Lower Voronoi Diagram
sites inside the sites of theUpper Voronoi Diagram
(the larger one), which we callCity Cells
.City Cell
is not a site in theUpper Voronoi Diagram
, but rather to a set of sites in a groupedLower Voronoi Diagram
. In the following steps, theCity Cell
is used as the basic unit.
-
After that, All of the outer edges of this
City Cell
are then set as Primary Roads.
- Recursively create a
Secondary Road
from the Boundary of theCity Cell
created above.
- Each Loop creates a straight road, with the number and direction of roads to be created from the current vertex determined based on a specified
Probability
.- The directions are
Left
,Forward
, andRight
, and aRandom Angle Offset
is added to these to create various shapes of roads.
- The directions are
-
Once we know which direction and what size roads will be generated, we need to validate that they are valid. Below, the new vertex is the end point of the road that will be created.
- Check 01. Is the new vertex inside the site?
- If not, cancel the road.
- Check 02. Is the new vertex close enough to other vertices?
- If the nearest vertex is already connected to more than 4 edges, cancel.
- If any road intersects the current road, cancel.
- Otherwise, merge the two vertices.
- Check 03. Is the new vertex close enough to another edge?
- If yes, divide the new vertex by the point where it intersects the nearest edge.
- Check 04. Is the new road intersect with another road?
- If yes, divide divide the intersecting roads. (new one and old one)
- If none of the above conditions apply, create the road as is.
- Check 01. Is the new vertex inside the site?
-
Repeat this procedure until reached at specified
Dimension(Stack)
.
-
Create the actual road mesh based on the road data we have created so far.
-
Use
B-Spline
to connect the straight roads into a single spline, and if there is an intersection, place aPre-Defined Intersection Prefab
at the location and connect the splines.- At this time, if you create a spline using only the previously created points, it will look quite rough, so we create a natural spline by creating
Sub-Point
s using the vectors to the previous and next points based on the created points. - Also, if there are vertices that are too close, including sub-points, during the creation process, merge them to maintain the structure.
- At this time, if you create a spline using only the previously created points, it will look quite rough, so we create a natural spline by creating
- Same as above generation.
- Since the previously created road mesh does not fully match the road vertex data, it is possible that the created roads may go off-site or not be attached, so check and fix this.
-
Primary Building
is a building that is created next to aPrimary Road
. -
It tries to place the building within a specified width area based on the vertex pair of the created
Primary Road Spline
.- If there is an overlap or insufficient space, the placement is canceled, and the rotation is set to face the road after placement.
-
Secondary Building
is a building that is created next to aSecondary Road
, placement method is the same as above. -
Additionally,
Parks
are placed at regular intervals, and if space is not available, buildings in that space are deleted andPark
is placed.