To access the tutorials in CityEngine, click Help > Download Tutorials and Examples.... After choosing a tutorial or example, the project is automatically downloaded and added to your workspace.
CGA parameters
Cities consist of a large number of objects. Controlling these by setting attributes of single buildings is tedious and close to impossible. In this tutorial, you'll first learn how CGA rule parameters are used.
- Open the mapcontrolTutorial_01.cej scene.
The opened scene contains two map layers (Terrain and Water) and a street network layer with lots of shapes. If you select a single lot now and check its attributes in the Inspector (Window > Inspector), there are no rule parameters assigned (the Rule Parameter pane is empty). This changes when you assign a rule file to the lot.
- Select the Streetnetwork layer in the Scene Editor.
- Click Shapes > Assign Rule File, and select the simpleBuildingShells_01.cga rule file.
- Select a single lot again.
Now there are attributes visible in the Inspector view, namely height.
- Click the Rule File link in the Inspector to open the assigned rule file.
- At the top, the attribute height is defined:
- Reselect the lot, and generate the building. The result is a building 80 meters high.
- Change the height value in the Inspector from 80 to 150. Note that the Rule item disappeared. The rule parameter height for this building is now overruled by the value you set. All other untouched lots still use the height value from the rule file.
- Regenerate the building, and note how the building height has changed.
This value is used in the rule file to define the height of the building.
// height value
attr height = 80
Control the skyline
In this section, you'll learn how to use maps to control the parameters of your cities.
Open the mapcontrolTutorial_02.cej scene if it's not already open.
Skyline map
If you generated some buildings with the current settings, your city would look similar to the following:
This is not very convincing, since all the buildings are the same height at 80 meters. A nice skyline would improve the look. Instead of setting the CGA shape attributes manually as you did in the first section, you'll use the red skyline map below to control the height of all buildings at once. The smaller image is the topography map, which indicates a lake in blue.
The red channel of the skyline map represents the height of the buildings in this area. When you compare the skyline map to the topography map, you'll see that a skyline forms around the corner of the lake. There is also a second center in the city at the top left.
- Create a new map layer by clicking Layer > New Map Layer > Mapping.
- Choose skylineMap.png as the mapping file.
- Deselect the Keep ratio button.
- Change the X and Z sizes to 3000.
- Make sure the alignment is set to centered (clicking the alignment icon changes the mode).
- Right-click in the Mappings area and click Add Row.
- Name the attribute skylineValue.
- You want the red channel of the image to be interpreted as height, so select red from the Channel drop-down list.
- Type 20 for the minimum value and 200 for the maximum value.
- Click Finish, and rename the created layer Skyline Map in the Inspector.
- Adjust the elevation offset of your new map layer in the Inspector to bring it to a position with better visibility. Use the alpha value to give it some transparency.
- Reassign the rule file to your lots so CityEngine can complete the connection.
- Select all lots.
- Click the dropdown in the height attribute and select Connect Attribute in the Inspector.
The Attribute Connection Editor dialog box appears.
- Click Layer attribute, and choose the new Skyline Map layer and the skylineValue attribute. After setting the source to the skyline layer, the value shows a ? character This means that the selection contains different values (all lot shapes have different height values).
- Select a single lot, and review its attributes in the Inspector view. The value of height is now connected to the skyline map.
- Select some lots around the Bay area and generate the buildings.
- Tall buildings will be created on large-area lots only.
- A random value is added to the incoming map value to give the skyline some variation.
- Select the lot layer in the Scene Editor.
- Assign the simpleBuildingShells_02.cga rule by right-clicking the layer > Assign Rule File.
Your scene should look similar to the following screen shot:
Height calculation with variation
// calc height with variation
getHeight(area) =
case area > 600 : rand(0,40)+height
case area > 200 : rand(0,40)+height/2
else: rand(15,30)
Control land-use types
You'll now learn how to use maps to control the land-use type of each building.
Open the mapcontrolTutorial_03.cej scene if it's not already open.
Control land-use types for buildings
A city often has areas of specific land-use types. This section describes how to set the attributes for three different land-use types. The following map shows commercial areas in blue, industrial areas in red, and residential areas in green:
Create the land-use map layer
Before creating the map layer, review the simpleBuildingShells_03.cga rule file, and look for the three CGA attributes: CGA land use types attributes// land use types
attr t_industrial = 0
attr t_commercial = 0
attr t_residential = 0
The map layer you create needs to have attributes with matching names.
- Hide the Skyline Layer by clicking the eye symbol in the Scene Editor.
- Create a new map layer by clicking Layer > New Map Layer > Mapping.
- Choose areatypes.png as the mapping file.
- Deselect the Keep ratio button.
- Change the X and Z sizes to 3000.
- Make sure the alignment is set to centered (clicking the alignment icon changes the mode).
- Right-click in the Mappings area and click Add Row.
- Add the following three mapping attributes:
- t_industrial > red channel
- t_commercial > green channel
- t_residential > blue channel
You'll evaluate these parameters in the rule file again, so the default minimum and maximum values of 0 and 1 are good generic mapping values for future use. - Click Finish to create the map layer.
- Rename the layer LandUse Map in the Inspector.
- Adjust the display offset of your new map layer in the Inspector view to bring it to a position with better visibility. Use the alpha value to give it some transparency.
- Select the new map layer, and check its attributes in the Inspector.
- Select all lots.
- Assign the simpleBuildingShells_03.cga rule file.
- Set the source of the land-use parameters to the LandUse Map layer.
- Generate all buildings in the scene.
- Alternatively, you can open the mapcontrolTutorial_04.cej scene and generate the buildings.
Now you'll evaluate the values of the land-use map.
Color type for land use.
// color declarations
red = "#ffaaaa"
green = "#aaffaa"
blue = "#aaaaff"
white = "#ffffff"
Color type for land use.
// Functions
landuseTypeColor =
case t_industrial > t_commercial && t_industrial > t_residential : red
case t_commercial > t_industrial && t_commercial > t_residential : blue
case t_residential > t_industrial && t_residential > t_commercial : green
else : white