Python Procedural City


This is a project that will procedurally generate a city.  The focus is to use Python inside Houdini to create an application that can assist in city creation without having to individual place all the structures.

Bounding Box Layout of the buildings

Test of the Buildings

Generate a City Map

The first step is to create a map that can be imported into Houdini. I found a website online that can generate random city layouts called the Medieval Fantasy City Generator. After making a layout that works for the design, I bring the image into illustrator, clean it up and rasteurize it. 

Convert to Geometry

Import the map as a Adobe .ai file, or an .eps file then convert it to geometry. At this point I manually select the blocks to be designated as commercial buildings and assign the primitive numbers to a group that will separate the blocks by color. 

Code to assemble the individual blocks and assign the building type.

Python Code Block 1

Import City Blocks and Sim Clusters


Code to import buildings and create the nodes that add the bounding box and the attribute parameters that will be passed through to the clustering simulation. 

Cluster the Buildings

Pop Attract is used to pull the buildings into the center so they can be placed over the individual blocks before being transferred to the main simulation. The left image shows the buildings scattered onto the points of a grid, the right image shows the buildings after the first simulation is run. The clusters are then stored in Null nodes where they will be randomly pulled and placed into the simulation.

Generate the City Blocks

The clusters are called and placed over the block shapes where they are filtered based on location. Buildings outside of the shape are removed, while buildings inside the shape are pulled to the outside of the shape using another Pop Attract. The buildings are now sorted as inside or outside the block space. Outside blocks are deleted and the space that remains in the center of the shape is then filled with smaller commercial buildings.

The Main Simulation

Block Shapes receive more filler buildings based on the offset space remaining in the center of the block. When the simulation is run, each block shape recieves a cluster of randomly selected buildings. The final output is a point cloud for each block that holds the reference number for each building that has been assigned. 

Import the Assembled Block Point Cloud 

Python is used again to import and create the file nodes that were written during the simulation. The original block position is recalled and the blocks are reassembled in their original positions. The blocks are then sent to the final section where the buildings are copied back onto them and the city is assembled.