Rule-based modeling

In CityEngine, building models are described through CGA rules. A CGA rule file consists of several rules that define how the actual building geometry is created. After a CGA rule file is assigned to a shape, the generation of the building model starting from this shape can begin.

Create and write a new rule file

A new CGA shape grammar rule file can be created by clicking:

New ... > CityEngine > CGA Rule File

A new CGA file is created in the rules/ directory of your project, and the CGA Editor is opened. In the CGA Editor, grammar authoring can be started by defining the building parameters: Therefore, the minimum and maximum building height are defined as rule attributes. These values can later be changed conveniently for single buildings in the Inspector.

attr minheight = 10
attr maxheight = 30

Every shape (lot or street shape) has a specific start rule that triggers a rule from the rule file. For example, lots generated in CityEngine have the start rule Lot by default. Select a single lot and look into the Inspector to see the current start rule.

Inspector view of a selected shape
Inspector view of a selected shape.

The Start Rule defines the first rule that is triggered from the rule set. Consequently, you can write the start rule for our building as follows:

Lot --> extrude ( rand ( minheight, maxheight )) Envelope

The lot will be extruded to a random height between minheight and maxheight.

Note:

Press Ctrl + Space in the CGA Editor to trigger the code completion feature. Possible commands and their parameters are listed as suggestions which makes coding CGA easier without the need to look up commands in the reference.

Assign rules and generate

The created rule file has to be assigned to the corresponding shapes (in the above case to lots):

  1. Select the lot layer Lots in the Scene Editor.
  2. Click ShapesAssign Rule File ... in the main menu.
  3. Select the file CGA file from the rules directory.
  4. Click OK.

    The selected lot now has an assigned rule file.

  5. Select lots in the Viewport.
  6. Click Generate in the toolbar in order to generate the buildings.

    You see below the generated buildings using a simple extrusion rule in the CGA file for deviation.

    The generated extruded models
    The generated extruded models.