Tutorial 5: Import initial shapes

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.

Import shapes from shapefiles and geodatabases

Import shapefiles into CityEngine

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
  2. In the File Navigator, locate the footprints.shp file in the data/shp_footprints/ folder.
  3. Drag and drop the file into the viewport.
  4. Import the data without a projection using Raw data in meters.

Object attributes

CityEngine imports attributes along with shapefiles.

  1. Select a single footprint.
  2. The object attributes are displayed in the Object Attributes pane of the Inspector.
    Object Attributes pane of the Inspector

Assign a rule file and generate models

You'll now generate simple extrusions on the imported footprints. The extrude.cga rule file uses the height object attribute to extrude the footprint to the defined height.

  1. Open the rule file and find the following code:
  2. attr height = 10
    
    @StartRule
    Lot --> extrude(height)
  3. Select all footprints in the 3D viewport.
  4. Assign the rule via drag and drop.
  5. Watch as the buildings are generated.
    Generated buildings
  6. Alternatively, open the footprints_from_shp.cej file to see the finished scene.

Import from a file geodatabase

Importing data from a file geodatabase is analogous to shapefile import.

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene. In the File Navigator, locate the file geodatabase folder footprints.gdb in the data folder.
  2. Note:

    The .gdb file format is displayed as a folder in the Navigator.

  3. Drag the footprints.gdb folder into the 3D viewport.
  4. A dialog box appears allowing you to choose the layers you want to import from the geodatabase.
    During import, CityEngine prompts you to choose a scene coordinate system. The coordinate system suggested in the dialog box is taken from the data found in the geodatabase.
  5. Click Finish to import the selected layers.

The dataset in the provided geodatabase is identical to the shapefile content. You can now apply the shapefile steps described above to your file geodatabase import.

Import PolylineZ shapes with additional CGA attributes

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
  2. In the File Navigator, locate the sphereCity.shp file in the data/sphereCity_shp/ folder.
  3. Drag the file into the 3D viewport.
  4. During import, CityEngine prompts you to choose a data coordinate system (the projection of the shapefile) for the sphereCity.shp file. The data in the shapefile is in meters, and is not georeferenced, so choose Raw data in meters.
    Select shapefile data coordinate system dialog box
    The sphereCity.shp file has no .prj file, so CityEngine also prompts you to define the scene coordinate system. The Select Scene Coordinate System dialog box allows you to do this.
  5. Choose Raw data in meters. By using the same coordinate system for data and scene, no reprojection is applied to the data on import.
    Select Scene Coordinate System dialog box
  6. A new shape layer called Shapes sphereCity appears in the Scene Editor, and the footprint shapes are visible in the 3D viewport.
    The polygons in this shapefile data have Z-values, resulting in 3D shapes in CityEngine.
    3D shapes shown in the CityEngine viewport

Attributes

Two special attributes are defined in this dataset:

  • ruleFile
  • startRule
Note:

Use this specific syntax in your GIS application to define which rule files and start rules are assigned directly after import. This way, you can save time by not manually assigning them. This is a special import behavior.

The attribute table in your GIS application will look similar to the following:

Screen shot of the attribute table

  1. Select a single shape (one face of the sphere).
  2. The object attributes are displayed in the Object Attributes pane of the Inspector.
    The rule file and start rule were assigned automatically during import.
    Rule file and start rule object attributes

You can now directly generate the models.

Generate the models

  1. Select all shapes of sphereCity in the 3D viewport.
  2. Generate the buildings.
    Generated buildings in the 3D viewport

Change the start rule

Change the start rule on individual shapes to change the generated model.

  1. Select a model in the 3D viewport.
  2. In the Inspector, click the Start Rule Select button.

    The Set Start Rule dialog box appears.

  3. In the Set Start Rule dialog box, choose Commercial as the new start rule. StartRules (rules with the @StartRule tag in CGA code) are displayed in bold font.
    Set Start Rule dialog box
    Generated buildings in the 3D viewport

Import shapes from OBJ

OBJ import

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
  2. Locate and select the pompeii_footprints.obj file in the data/obj/ folder.
  3. Right-click the file, and choose Import.

    The OBJ import dialog box appears.

  4. In the OBJ import dialog box, uncheck Import as static model.
    OBJ import dialog box
  5. Click Finish.
    Imported OBJ file

Assign a rule file and generate models

You'll now generate simple extrusions on the imported footprints. The extrude.cga rule file uses the height object attribute to extrude the footprint to the defined height.

  1. Select all footprints in the 3D viewport.
  2. In the File Navigator, locate the extrude.cga rule file in the rules folder of the project and drag it onto the selected footprints in the 3D viewport.
    The rule file extrudes all footprints to a height of 10.

Shapes versus static models

OBJ and Collada DAE files can be imported as shapes or as static models as follows:

  • Shapes—Serve as a base for CGA generation. A typical example is footprint data.
  • Static models—Can be scaled, rotated, and translated after import but cannot be processed further with CGA. Typical examples are landmark models.

If desired, open footprints_from_obj.cej to see the finished scene.

Import volumes

Import volumes as shapes

In some cases, it's easier to model volumes in an external application than to describe them with the CGA grammar. This section shows how a crude building volume, modeled in Maya, can be imported into CityEngine, and how its facades can then be refined using CGA rules.

The building volume in the following image was modeled with conventional methods in Maya and exported as an .obj file:

Building volume model

Note:
An analogous workflow can be applied using multipatch data from a .shp, .gdb, or .dae (Collada) file instead of OBJ data.

Import an .obj file into CityEngine

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
  2. Locate and select the Building_1.obj file in the data/obj/ folder.
  3. Right-click the file, and choose Import.
    The OBJ dialog box appears.
  4. In the OBJ import dialog box, uncheck Import as static model.
  5. Click Finish.
    OBJ import dialog box

    A new shape layer called Building_1 appears in the Scene Editor, and the data is displayed in the 3D viewport.

    Building_1 in the 3D viewport

Write the rule file

The building volume's name, Building_1, already defines its start rule Building. Consequently, you need to have Building as the starting rule. You need to align the coordinate system of the imported model to CityEngine’s yUp system. This is done with the alignScopeToAxes() CGA command. After that's done, you can identify the different faces of the imported volume with the component split comp(f) . You'll use the top selector for the roof faces and the side selector for the facades. All you do in this step is color the roof shape to see that the faces are identified correctly.

Building -->
	alignScopeToAxes(y)
	comp(f){top : color("#ff0000") Roof. | side : Facade. }
  1. Select the building shape in the 3D viewport.
  2. In the File Navigator, locate the importedVolume_01_markFaces.cga file in the rules folder of the project, and drag it onto the selected shape in the 3D viewport.
    The imported building volume is generated with a simple rule to identify the faces. Red: top faces (roof); Grey: side faces (facades):
    Generated imported building volume

Once the faces are identified correctly, you can continue the rule set. Since these faces are modeled outside CityEngine, their orientation is not necessarily how you need them for your rule operations. For the Facade rule, start with the alignScopeToGeometry(zUp, auto) CGA command. With this operation, the scope of the facade shape is aligned to its lowest edge, with z facing outward. This ensures that you operate with identically oriented scopes on all facade faces.

Facade -->  
alignScopeToGeometry(zUp, auto)
split(y){3.5 : Groundfloor | {~3 : Floor}* }

The importedVolume_02_facades.cga rule file has a set of rules that adds more details to the building's facades. See the ShapeGrammar tutorials for help regarding writing CGA rules.

Generate the building again using this rule set.

  1. Select the building shape in the 3D viewport.
  2. In the File Navigator, locate the importedVolume_02_facades.cga file in the rules folder of the project, and drag it onto the selected shape in the 3D viewport.
    The volume_from_obj.cej scene file contains the imported model with the rule file assigned.
    Imported model with rule file assigned

Import landmarks as shapes

If you have premodeled, textured assets you want to use in your scene, those can be imported as well.

Note:

Supported formats are Wavefront .obj, Collada .dae, .kml, and .kmz. (The last two are basically Collada files with georeference.)

Import a .dae file into CityEngine

  1. Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
  2. Locate and select the building_0.dae file in the data/dae/ folder.
  3. Right-click the file, and choose Import.
    The OBJ import dialog box appears.
  4. In the OBJ import dialog box, uncheck Import as static model.
  5. Click Finish.
  6. A new shape layer called building_0 appears in the Scene Editor.
    building_0 in the Scene Editor

Convert static models to shapes

If you have imported static models and want to continue working on them with CGA code, you can convert them to shapes.

To do so, right-click the model, and click Convert Models to Shapes.

You can do the same with CGA-generated models.

Apply a CGA rule

If required, imported shapes can be processed further with CGA rules.

  1. Assign the landmark.cga rule file.
  2. Generate the model.
    The Style Manager dialog box shows the four style options for importing with CGA rules.
    Style Manager dialog box for landmark.cga
  3. If desired, open landmark_as_shape.cej to see the finished scene.