About CityEngine Blog


CityEngine is a great tool that is able to create large scale models, mainly of cityscapes, quickly, and with the ability to make adjustments based on a rule file in a procedural manner.

I hope to show you some of the work I have done with CityEngine creating a variety of models across a range of projects. I have mainly used the software for planning applications but have learnt a great deal of the potential for other applications.

I want to concentrate on the writing of rule files which is the core use of CityEngine. Without rule files no 3D content can be generated and this is very important to understand. I will also strive to bring news and updates regarding CityEngine as well.

I hope you find what I share useful and please feel free to share and contribute your thoughts and experience.


Sunday, 10 November 2013

TikiTown 3 - CGA creation - Tiki Spike


I really wanted the 'spike' of the Tiki to be a stand out feature and so decided that it would be the tallest part of the city. As previously mentioned, the Spike' starting geometry was a single parcel, this would allow me to create a building that is stepped in appearance. The code for this part of the city is posted at the bottom, along with a link to a web scene containing this feature.

TikiTown Spike

The spike would actually prove to be the easiest part of the city to code . It consists of just one input feature and so the code only has to work on one parcel. I wanted to create other parts of the city in a similar way and so I expected to use parts of this code again.

The first step was to again extrude the entire parcel to give the island like appearance, I then carried out a comp(f) split to selected the top as the base on which to keep building. The shape was then split in the longest (x) direction  into approx. 15m sections. The split index and split total values were stored which would be used to help create the stepped appearance. Instead of carrying the values continually I have set the values to two hidden attributes - SpikeIndex and SpikeTotal, these can be recalled at any point in time without having to duplicate any code. A 3m gap between each building footprint was created, except for the last one footprint where there is no need to create a separation. To do this, using the SpikeIndex and SpikeTotal I can select the just the last footprint and pass it to the next level whereas the rest of the footprints are subject to another split that takes the 3m away.


 The footprints are now ready to extrude and again I used the SpikeIndex and SpikeTotal values to generate a height value. I didn't really care what height that the buildings should be but that it should be taller than anything else in the city. The extrude function is a little complex in that it needed to include a reverse function so that the lowest index footprint receives the highest heights. This is achieved by subtracting the SpikeIndex from the SpikeTotal (plus one). The resulting height value is multiplied by 10 to give a nice height for extrusion.

The resulting building can now be split into floors and in this case instead of simply dividing by a single floor height I decided to make a little more use of the SplitIndex value and to use this as a way of splitting floors. I buildings that as they became taller the floor heights became smaller.


Another Comp(f) split was carried out to select the side facade of the buildings to which a 'y' split was carried out to generate a floor separator whose value is based on the height of the floor divided by 5. The last stage of the process was to create a simple facade that included tall, slim windows and to add colours to the entire complex. The outcome kind of reminds me of a casino / hotel in Las Vegas...



Here is a link to a web scene containing the Spike complex and the code for the TikiSpike is below:

/**
 * File:    TikiTown.cga
 * Created: 1 Jan 2013 02:26:48 GMT
 * Author:  ellawayc
 */

version "2012.1"

##-----------------------------------------##
## Hidden Attributes ##
##-----------------------------------------##
@Hidden
attr SpikeIndex = 0

@Hidden
attr SpikeTotal = 0

##-----------------------------------------##
## Rules ##
##-----------------------------------------##

@startRule
Spike -->
      extrude(2)
      comp(f){top : Spike1 SpikeBaseTop | all : Base.}
     
Spike1 -->
      split(x){~15 : Spike2(split.index,split.total)}*           
     
Spike2(idx,n) -->
      set(SpikeIndex, idx)
      set(SpikeTotal, n)
      Spike3
     
Spike3 -->
      case SpikeIndex == SpikeTotal -1 : Spike4
      else : split(x){~12 : Spike4 | ~3 : NIL}

Spike4 -->
      extrude((SpikeTotal-SpikeIndex+1)*10)
      split(y){~SpikeIndex+1*3 : Spike5}*
     
Spike5 -->
      comp(f){side : SpikeFacade | top : SpikeRoofs | all : SpikeKeeper}     

SpikeFacade -->
      split(y){~1 : SpikeFacade1 | scope.sy/5 : SpikeFloorSeparator}
           
SpikeFacade1 -->
      case scope.sx < 1 : SpikeWall
      case scope.sx < 5 :
            split(x){{~scope.sx*0.5 : SpikeWall | ~1.2 : SpikeWindow}* | ~scope.sx*0.5 : SpikeWall  }     
      else :
            split(x){{~2 : SpikeWall | 1.2 : SpikeWindow}* | ~2 : SpikeWall }
           
SpikeWindow -->
      setback(0.1){all : SpikeWindowFrame | remainder : SpikeWindow1}  
     
SpikeWindowFrame -->
      extrude(0.3)
      t(0,-0.3,0)
      color("#808080")  #Grey
     
SpikeWindow1 -->
      t(0,0,-0.3)


SpikeFloorSeparator -->
      color("#808080")  #Grey
     
SpikeWall -->
      color("#003366")  #Dark Blue       
     
SpikeRoofs -->
      color("#808080")  #Grey
     
SpikeBaseTop --> 
      setupProjection(0, scope.xy, 2, 2)
      projectUV(0)
      texture("pavement.jpg")