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
- Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
- In the File Navigator, locate the footprints.shp file in the data/shp_footprints/ folder.
- Drag and drop the file into the viewport.
- Import the data without a projection using Raw data in meters.
Object attributes
CityEngine imports attributes along with shapefiles.
- Select a single footprint.
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.
- Open the rule file and find the following code:
- Select all footprints in the 3D viewport.
- Assign the rule via drag and drop.
- Alternatively, open the footprints_from_shp.cej file to see the finished scene.
attr height = 10
@StartRule
Lot --> extrude(height)
Import from a file geodatabase
Importing data from a file geodatabase is analogous to shapefile import.
- 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.
- Drag the footprints.gdb folder into the 3D viewport.
- Click Finish to import the selected layers.
Note:
The .gdb file format is displayed as a folder in the Navigator.
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
- Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
- In the File Navigator, locate the sphereCity.shp file in the data/sphereCity_shp/ folder.
- Drag the file into the 3D viewport.
- Choose Raw data in meters. By using the same coordinate system for data and scene, no reprojection is applied to the data on import.
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:
- Select a single shape (one face of the sphere).
You can now directly generate the models.
Generate the models
- Select all shapes of sphereCity in the 3D viewport.
- Generate the buildings.
Change the start rule
Change the start rule on individual shapes to change the generated model.
- Select a model in the 3D viewport.
- In the Inspector, click the Start Rule Select button.
The Set Start Rule dialog box appears.
- 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.
Import shapes from OBJ
OBJ import
- Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
- Locate and select the pompeii_footprints.obj file in the data/obj/ folder.
- Right-click the file, and choose Import.
The OBJ import dialog box appears.
- In the OBJ import dialog box, uncheck Import as static model.
- Click Finish.
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.
- Select all footprints in the 3D viewport.
- 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:
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
- Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
- Locate and select the Building_1.obj file in the data/obj/ folder.
- Right-click the file, and choose Import. The OBJ dialog box appears.
- In the OBJ import dialog box, uncheck Import as static model.
- Click Finish.
A new shape layer called Building_1 appears in the Scene Editor, and the data is displayed 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. }
- Select the building shape in the 3D viewport.
- 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):
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.
- Select the building shape in the 3D viewport.
- 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.
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
- Open a new scene file by clicking File > New > CityEngine > CityEngine scene.
- Locate and select the building_0.dae file in the data/dae/ folder.
- Right-click the file, and choose Import. The OBJ import dialog box appears.
- In the OBJ import dialog box, uncheck Import as static model.
- Click Finish.
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.
- Assign the landmark.cga rule file.
- Generate the model. The Style Manager dialog box shows the four style options for importing with CGA rules.
- If desired, open landmark_as_shape.cej to see the finished scene.