Basic Training

Rule Based Modeling with CityEngine

One of the amazing innovations introduced by the developes of city engine is a scripting language for Computer Generated Architecture (CGA). This language has many built-in modules for parsing and assembling shapes. It based on a rule-oriented form of logic known as Shape Grammar. This tutorial presents a basic understanding of the city engine CGA grammar that begins with an empty CityEngine view, creates a subdivision of Lots, uses logic to parse the lots into open space and building lots, extrudes buildings and then produces a report. The script provides several parameters that may be adjusted from the CityEngine user interface.

This tutorial is based on two tutorials produced by ESRI: Basic Shape Grammar and Reporting. I've rearranged them a little bit to suit my way of seeing the world. But there was nothing wrong with the originals.

Download Tutorial Dataset

Download this zip archive and extract its contents.

  1. Use CityEngine to create a new project in our default workspace. Then we'll go into the sample dataset and copy the contents of the Data, Rules and assets folders to the corresponding folders in our project.
  2. Create a new Scene and set its coordinate system to State Plane > NAD83 Feet > Massachusetts FIPS 2001 . This is so we canuse a shape file later.
  3. Use the Polygonal Street Creation button to create a ring of streets. Make sure to zoom out enough so that you are creating a block that is large enough to hold 10 or 20 building lots.
  4. The lots should be drawn in automatically. Select them all by unrolling the StreetNetwork layer in your Scene explorer, right-clicking Blocks and choose Select all objects in same layer.
  5. Now we will assign a rule from the reporting_01_pbc.cga script.
  6. It is best if you set the Subdivision Method to Offset Subdivision in the Inspector > Shape Parameters > Block Parameters.
  7. Look at what you can see in the Reports panel of the Inspector window. It should be a tally of the amount of openspace and built space in the project.
  8. Play with the sliders in the Rules > Reporting_01_pbc section of the Inspector Window. Notice how the report changges dynamically with the generated project!

Hacking CGA

So there you have yet another demonstration of a mysterious rule. Now lets dig into a rule file that we may have a chance to understand. I have taken the rule file from ESRI's CGA Reporting tutorial and added verbose comments to it. INthe next section we wil ltake this rule apart and learn how to modify it.

Editing a CGA Script

  1. Go to your Rules folder and find the rule file Reporting_01_pbc Right click on it and choose Open with CGA Editor.
  2. Maximize your editor window and change it to Text Mode with the Button at the left end of the button bar.
  3. Notice the verbose comments on the right side of the window. These provide a play-by-play of what is happening in the script. Text in ALL CAPS can be entered in the CGA Programming Reference for more information.
  4. Go through these and try making some suggested alterations and check out what they do.
  5. When you make changes to the script use File > Save to save it. Then you can use the Reseed and Generate button next to the Generate button at the top of the screen. .
  6. Once you start hacking CGA, its hard to stop!!

GIS Driven Attributes

In our data package for today, I have included a three shape files: Parcels, BuildingShells and ZoningDistricts. These will demonstrate how rules interact with GIS data. You can also use the parcels to demonstrate how the rules that we used on synthetic parcels in the previous demo can also be applied to shapes that come from GIS.

  1. Look at the data in GIS. Check the attribute tables. Note the ZoneTYPe and CE_ZoneType fields. it should be noted that using hyphens in data values is apparently a no-no in CityEngine. Or maybe there is some purpose that hyphens serve as a delimiter that makes them a no-no for all other purposes.
  2. Drag our shape files into the view.
  3. You probably have to flatten the building shells since their 3d vertices seem to be all over the place.
  4. Select all of the buildings and apply the rule, FeatureReader.cga. Notice that it has a couple of user-modifiable options.
  5. Take a look into the script. The comments explain each line.
  6. While I was working on this I noticed that if you click the little icon next to the Adjustable attributes in the inspector window, that you can do some very useful GIS-like things. Like, for example driving the heights of the buildings using the Max-Hgt field from the ZoningDist shape file. That is pretty cool.

Modeling Buildings

So all of this CGA is pretty interesting. The one thing we haven't see ishow it does buildings. I've included a script, SimpleBuilding02.cga in our Rules package that I took from the ESRI tutorial, Basic Shape Grammar. Somebody named Andi wrote this one and he wrote some useful comments. The ESRi tutoriak explains this one pretty well, so I'll let you look at their documentation for the details on how this works.

Alert

If the textures do not wender when you apply this rule, try replacing their references in the script to include thwe name of your CIty Engine Project. That is, if your project is named cga_play then change the path references to the resources listed in your script, to: "cga_play/assets/facades/textures/shopdoor.tif". I think that this may be fixed by properly setting your preference for Default City Engine Workspace. Look here for more updates on this.


Challenge Exercise!