Getting started - part 2

Note

You must read part 1 before!

In this second part, you’ll learn how to make your cities with buildings and roads that never overlap. You will import the library of props that comes bundled with SceneCity, specify what buildings and roads assets to use, and tell the generator how you want them placed. The cities are restricted to parallel and perpendicular directions for now. The roads cannot be curved, cannot go in any random direction or meet at angles other than 90 degrees. These restrictions will be lifted in later versions.

Finally you will learn how to prepare your own buildings and road portions assets so that you can use them with SceneCity.

By the end of this tutorial, you’ll be ready to use SceneCity to its fullest to create extremely large cities, as detailed as you want, and with any asset, so keep reading (and don’t forget to have fun ;)

Creating and previewing the layout of the city

The foundation of a non-overlapping city is a grid. Everything will be placed on the cells of that grid. However you are in charge of the size of the grid, what you store in that grid, and how the generator should use it to place different things on it, such as the roads and the buildings.

Create a new city graph, call it something like Tutorial city 2. Add and connect the following nodes:

  • City layouts ==> grid
  • City layouts ==> non-overlapping boxes
  • City layouts ==> blender image from grid
_images/1.png

You now have a blank grid. You give it to a new layout which will put values inside that grid. Then the last node will draw that grid based on the values inside, to have an overview.

Before explaining in more details the options of each node, click Add new color on the last node, four times, then set it like below. Then click on Create / update image and display the image that has just been created. You should have something like this.

_images/2.png

Warning

The exact colors you choose don’t matter, use any you like, BUT the texts of the key/value fields do matter!

The resulting image is a map of your city, of where the roads and buildings will be. Each pixel is 10 meters wide, and the colors represent roads for black pixels, residential districts for green pixels, industrial districts for yellow pixels, and commercial districts for blue pixels. Note that the types of districts are just those by default, they are simply names, and you can have as few as one district type to as many as you need.

Let’s see in more detail the important stuff here.

The grid

Let’s talk about the grid node first. You can set two important values: the overall size of the grid, which is how many cells it has on each side. And the size of each cell, in meters or blender units (I consider 1 meter equals 1 Blender unit, by convention). Each cell is a portion of land in your city, onto which you’ll put things. Therefore in this example a grid of 100 by 100 cells, with a cell size of 10 meters, represents a land of 1km by 1km.

How do you choose the size of the cells? A cell is the smallest unit when you layout your city. You will define the size of your assets (roads and buildings) in terms of cells, so for instance you could make (or have) a building 2 cells wide by 4 cells long. Which means 20m wide by 40m long if a cell is 10m wide. However it’s most important for the roads. Currently the road portions can only be exactly 1 cell wide by 1 cell long. So if you want your roads to be 20 meters wide, you should set your cell size to 20 meters. And obviously a too small cell size would not make much sense if the roads are then only a few meters wide, like 2 meters. In future versions the roads will be much more flexible. Also the included library of assets is built for a cell size of 10m, which is the default, so leave it at 10 meters.

What’s in the grid?

Each cell of the grid contains key / value pairs. The keys and values can be any text that you choose. For example it can be district = residential, road = any, blender = awesome. Each cell can also have multiple key / value pairs. Each key can only have one value, so you cannot have in the same cell district = residential and district = commercial, it’s either one or the other.

Here is an example of what a grid might contain:

_images/grid_content_example.png

The layout

The layout node generates boxes separated by separators. You can control their size. You can also tell what key / value pairs to store in the grid cells of the boxes and separators. This effectively creates districts and roads, and those key / value pairs will be used in the next steps to control where to put the buildings and the roads.

For the roads their key / value do not matter because there’s no way for now to have different road types in the same city (in future versions it’ll be possible). For the buildings however it is possible to have different districts, so decide how many district types you need, then give them a name, for example commercial, residential, industrial. In this tutorial we’ll keep everything at their default values.

_images/non_overlapping_boxes_example.png

An example of a larger city layout of 300x300. But for yours don’t make it too large to begin with, 100x100 is very large already.

Congratulations, you have the map of a city now. If you don’t understand a concept such as the grid, what it contains or what the layout does, you should read this section again. Otherwise this section is completed and you can keep reading below, you’ll add the roads in the 3d scene.

Adding the roads

Let’s put the road models where they should be. We’ll use the ones that come with SceneCity. Later in this tutorial you’ll see how to use your own, but for now we’ll concentrate on understanding how to let SceneCity place them in the 3d scene.

Go to the scene options, in the SceneCity panel. Click on Import library of roads and buildings in active layers.

_images/3.png

You should see several models appear.

_images/4.png

They are now part of your blend file, in Blender’s terms they have been appended to the file. You can modify or delete them, but for now leave them as is.

Warning

A common mistake at this step is to move the imported assets around in the scene. Those props are made of several objects grouped together (for most of them). If you’re not familiar with object groups in Blender, know that a group has an origin that is set in the group setting, found in the object tab of the properties panel, when you select any object part of that group. Moving the objects of the group around, without setting the group origin again accordingly, is like moving a whole mesh in edit mode: visually you have moved things around, but for Blender the mesh or group is still at the same location. Its center or origin hasn’t moved. If you do that, later in your city you’ll see buildings and roads that look out of place. But actually they’re not, their centers are correctly placed, it’s the objects within those groups that are misplaced, because you forgot to set the origin of the groups back to the actual, real center of the buildings/roads when you moved them.

In another layer add an instance of the 3 following groups that have just been appended:

  • road_1x1_1_straight
  • road_1x1_1_intersect3
  • road_1x1_1_intersect4

Note

How to add a group instance: with the mouse in the 3d viewport, SHIFT+A -> Group instance. Start typing road to see all groups with their name starting with road.

You should have something like this:

_images/5.png

In the city graph, add the following nodes and connect them like below:

  • City objects ==> objects getter
  • City roads ==> static road portion

Fill the name of the straight road portion object instance you added before. And make sure the road type is set to straight.

_images/6.png

The first node converts a Blender object to a SceneCity object (or several if the object has children, but this feature is not ready yet). The second node converts a SceneCity object into a road portion. So what you just did is tell SceneCity that the object road_1x1_1_straight is a straight road portion, and it is now ready to be used, but before that…

Select the nodes and duplicate them twice, for the other two portion types: intersection-3 (or T-crossing), and intersection-4 (or X-crossing).

_images/7.png

To instantiate those road portions and put them at the correct location, add the following two nodes, and connect them like below:

  • City roads ==> road portions collection
  • City roads ==> road portions instancer

Add three input socket to the collection by clicking on Add road portions, and fill the Place on grid value field with road = all.

_images/8.png

The collection node is used to group several road portions together (of the same or different types), and let other nodes use them as a whole. When several portions of the same type are available in the group (eg 2 different straight portions) they are chosen randomly. When that happens, you can favor one over the others by setting different probability weight: a portion with a weight of 2 is twice as likely to be chosen as a portion with a weight of one.

The road instancer node will place the portions where they should be, and rotate them accordingly also. But you have to tell it what parts of the grid contains the roads. It will check all the cells of the grid, and each time it finds a cell with a key road with the associated value all, it will place a road portion there. The output of this node is a bunch of SceneCity objects, so you need one last node to transform those objects back into Blender objects.

Finally add the last node: City objects ==> objects instancer.

_images/get_started2_roads_instances_objects.png

Set the name prefix of the future objects to Road, set the instance method to Dupli verts, and click the Create objects button. You should have something like this appear:

Note

The creation of the instances should be almost instantaneous, but for larger cities it’ll take more time. In that case Blender will freeze while SceneCity works in the background. The only way to see the progress is to open Blender’s console (on Windows it’s in the window menu -> toggle system console) and watch the progress report. You must open it before clicking the button to create the roads.

_images/get_started2_roads_objects_viewport.png _images/get_started2_roads_objects_render1.jpg _images/get_started2_roads_objects_render2.jpg _images/get_started2_roads_objects_render3.jpg

The last node created “virtual” instances of the road portions because we set it to dupli verts. So here is what it created in the scene

_images/get_started2_roads_objects_outliner.png

Under a parent named like the name prefix you set (Roads), you have all the different objects that make all the road portions, which in that case are the three object groups. The created object hierarchy setup is for dupli verts, a method of object duplication in Blender: it places a virtual copy of the same object at each vertex of a mesh (note that duplication and instantiation are interchangeable terms). By virtual I mean that the copy only exists for rendering, and cannot be manipulated like a regular object in the scene. It’s the most efficient duplication method Blender has, performance-wise and memory-wise. On the other hand each instance cannot be manipulated individually. For that you need the second instantiation method: individual objects.

The second instantiation method, individual objects, creates objects sharing the same datablock. It has the advantage that you can do much more with an object than with the dupli vert method: transform them (move, scale, rotate), change their datablock, apply modifiers etc… It is however a much much less efficient method, it cannot scale at all beyond a few hundred objects, so in practice it should not be used or only for a limited set of object instances.

Note

DO NOT enter edit mode for the meshes used to place the instances (they have dupli positions for in their name). Doing so will reset the rotation of all their vertices, and therefore of all the associated instances.

Note

There are additional instances that look out of place, at the origin of the roads. DO NOT delete them, they are necessary and part of the dupli verts setups. They won’t appear in the renders, only in the viewport, that’s the way dupli verts works in Blender.

Adding the buildings

This step is a lot similar to the roads.

First in the same layer as the one you added the group instances for the roads, add an instance for each of the buildings. You should have 11 buildings in total: 4 small buildings (1x1 cell), 3 medium (2x2) buildings, and 4 large (4x4) ones. You should have this:

_images/get_started2_buildings_model_instances.png

In the city graph, add two new nodes:

  • City objects ==> objects getter
  • City buildings ==> static building portion

Then copy/paste the name of the first small building, and set its size to 1 grid cell by 1 grid cell. Remember that our grid is set to 10 meters per grid cell, and the included buildings, just like for the roads, have been modeled in increment of 10 meters for their X and Y sizes.

_images/get_started2_buildings_nodes1.png

With these two nodes you have just described a building of 1 cell on X by 1 cell on Y, from an existing Blender object. Do the same for all the other buildings. Don’t forget to set their size correctly. You should have something like this:

_images/get_started2_buildings_nodes2.png

Note

When extending the graph, copy and paste the existing nodes (and the object names from the properties panel, when object names are needed), it’ll be much faster.

Just like for the roads, add the following nodes:

  • City buildings ==> buildings collection
  • City buildings ==> buildings instancer
_images/get_started2_buildings_nodes3.png

Connect all the buildings to the collection node. This will allow them to be used as a group. It’s very similar to the collection of roads.

On the instancer set the district to comm (short for commercial) because that’s the kind of district the included buildings are made for. If you changed, or will change, the key and/or value for the districts, don’t forget to set it here also. For instance, if on the layout node, instead of district you set block_type as the key, and instead of comm you set commercial as the value, then enter block_type = commercial on the instancer node.

By default the buildings will orient to the roads. Again if you changed the key / value pair of the roads, you must set it here as well, otherwise the buildings will have random rotations, and not be facing the roads.

Finally we just need to add an object instancer node:

_images/get_started2_buildings_nodes4.png

Set it to dupli verts as well, and specify the name prefix of the future objects. Create the objects.

Note

The same kind of progress report is available in Blender’s console, just like for the roads.

_images/get_started2_buildings_viewport.png

Your viewport may be slow at that point, when there are too many objects visible in the scene. Even with dupli verts, Blender is not very optimized to efficiently draw lots of objects in the viewport. Fortunately this is not the case when rendering with Cycles, it is extremely optimized and won’t break a sweat even with buildings stretching to the horizon. To fix the slow viewport issue, enable Hide objects in viewport on the instancer node. Re-create the objects.

_images/get_started2_buildings_nodes5.png

You will see the verts where each building is, but no longer the buildings themselves. Again, this is only in the viewport for performance reasons, and will not affect your renders.

_images/get_started2_buildings_viewport_hide_objects.png

Note

What if you need to see some buildings in the viewport, for example to place the camera precisely. A solution is to show only some buildings, and hide all the others. It is done by creating a different kind of district for which you use a new objects instancer node. On this node you disable the Hide objects in viewport option. Later features will be added to make this easier.

Note

Again, what if you want to manipulate some buildings. Changing the instantiation method to Individual objects is not practical for even moderate amounts of objects. And entering edit mode to change the corresponding verts of the buildings you want to edit is not possible because all the verts will automatically lose their rotation (Blender’s behavior). A solution is to either leave some districts empty and fill them yourself by hand. Or use the Individual objects instantiation method for only some districts, that are as small as possible in the city to avoid having too many individual objects in the scene. Later features will be added to make this easier.

_images/get_started2_buildings_render1.jpg

Only the commercial buildings are present. The other districts (residential and industrial) are missing because we haven’t specified any buildings for them yet.

_images/get_started2_buildings_render2.jpg

Congratulations, you have roads and buildings! All fitting together nicely. But wait a minute, there are holes in the city, empty districts. That’s where the other district types are: residential and industrial. We haven’t taken care of them yet, and that’s what we’re going to do next.

Creating your own buildings

Up to this point you have been using the assets included with SceneCity. Now you’ll learn how to create and use your own. There are a few easy conventions to follow for SceneCity to use your assets. The hard part is in making great asset though ;)

First, a building can be a mesh or an object group. But in both cases, in the end it has to be in the form of a Blender object, so you can feed it to the Objects getter node we saw earlier.

Secondly, you have to decide what size it is, in terms of grid cells and in Blender units. The smallest building for the grid cells in this tutorial (10 meters wide) is 10m by 10m (1 meter equals 1 blender unit by convention). A building can be 1x1 cells, or 2x2, 4x2, 10x20, etc…

Thirdly the mesh or group origin must be at the exact center of the building on the XY (horizontal) plane. For instance a 10mx10m building should have its bounding box from -5m to +5m on both X and Y. A 20mx40m building would have its bounding box from -10m to +10m on X, and -20m to +20m on Y. On Z, zero is the ground so you shouldn’t model anything below it, though you can if your city has no ground or you’ll see underground somehow. In all cases the buildings can be as short or as high as you want.

And lastly the building’s front side must be facing its local positive x.

Start modeling it if it’s a mesh, or arranging the objects together if it’s a group.

Here are 2 simple example buildings, as object groups, I modeled for the sake of this tutorial:

_images/get_started2_buildings_residential_viewport1.png

First I modeled a simple base mesh. Notice that the centers (the two little dots) are at the center of the houses, this is crucial! Then I modeled a fence mesh, duplicated and placed several instances all around the houses.

_images/get_started2_buildings_residential_viewport2.png

Finally I grouped the objects together. One group for the small house, and another for the larger one.

Warning

A common mistake people make with groups in Blender (and this is because Blender’s groups are useful but not user-friendly, at least in Blender 2.79) is to move the objects of the group around, as a whole, but they forget to also change the group origin. The typical symptom, if you forget to do that, will be buildings that look out of place in the city. Although the buildings instances’ origins will be correctly placed in the city, the objects inside the groups are not correctly centered around their group’s origin.

_images/get_started2_buildings_residential_viewport3.png

Make sure that the group origin is set to the center of the building. And this must be done each time you move around the objects of the building, as a whole. Of course simply moving props inside the group, like a fence object, does not change the center of the building, so in that case the group origin stays the same.

You’re not limited to buildings with the same dimension on both axes. You can have a 20 by 40 mansion for instance:

_images/get_started2_buildings_residential_viewport4.png

Once you have your residential buildings models ready, you add them to your city graph, just like you did before in this tutorial.

_images/get_started2_buildings_nodes6.png

At this stage you have two objects instancer nodes: one for the commercial buildings, and one for the residential buildings. You can keep the graph like this if you want, so you can create or delete each district type separately, and use different instantiation method if you need.

_images/get_started2_buildings_nodes7.png

Another option is to have only one instancer node no matter how many districts you have. This is useful to create or delete them in a single action. It’s done with the Objects add node (found in the City objects category), like this:

_images/get_started2_buildings_nodes8.png

Either way, create the buildings instances in the city, and you should have something like this:

_images/get_started2_buildings_residential_render1.jpg

The residential districts added, with simple houses modeled for this tutorial. The industrial buildings are still missing.

You know how to make and use your own buildings with SceneCity. An exercise you can do is to model your own residential and industrial buildings, then add them to the city.

Creating your own road portions

Two types of Blender entities can be used for the roads: meshes, and groups of objects.

There are 3 road portion types you must create. Just like Lego blocks, the road portions must fit together to give the illusion of continuity from a portion to another. To achieve this, you must follow certain conventions when creating your models. SceneCity will then instantiate (meaning creating copies) and place the instances in the scene to form the entire network. It will assume you follow the conventions properly. If you don’t, the network will look odd.

_images/get_started2_roads_types.png

The portions must follow a few conventions common to all of them, and some specific to each.

Here are the common conventions:

  • A portion is 1 grid cell wide by 1 grid cell long. In future versions this limit will be lifted.
  • Just like for the buildings, the model or group origin must be at the center on the XY plane.
  • Local Z=0 is the ground level.

Here are the conventions specific to each road block type:

  • Straight: portion of a straight road along the local X axis.
  • T crossing: when 3 directions meet: along Y (+Y and -Y) and +X.
  • X crossing: when all 4 directions meet: along X and Y.

The number of lanes is your choice, but the more lanes you want, the bigger you must make the cells of the grid (again because a road potion can only be 1x1 grid cell), see the section above about the grid.

Next steps

Part 2 completed, bravo! It was a bit long, but you’ve been through major city-construction concepts. If you feel you don’t fully grasp everything, that’s okay. It may be a lot to swallow, especially in one session, and even more if you’re not a regular Blender user. What you need now is practice, if you haven’t done it along the way. So what you should do is to try and make your own city now, and use this page as reference. And once it is done you’ll have all the knowledge necessary to use SceneCity in your own projects.

The rest of this documentation is written as a reference, and not in a step-by-step fashion as in this page. You should go directly to the specific node page you need, or socket type, to understand the exact thing you need.

Have fun, and don’t forget to subscribe to the newsletter (see website, bottom of the page) or my twitter for future updates and news. More is coming ;)