CGA : Simple Roofs

7872
12
07-11-2012 04:51 AM
MatthiasBuehler1
Frequent Contributor
Dear CityEngine users,

I've been asked to create a thread where users can learn how to create roofs in CGA. So I've taken the chance and created the following code for CityEngine (2011.1 and newer).

Please note that this code was specifically written to define precise heights of the roof volume, to make sure no matter which roof type a building has, the resulting 'ridge height' is the same. Came as an input from an other user.



Let me know if there's questions !

Cheers !

Matt
Esri R&D Center Zurich


@Group ("BUILDING VOLUME", 0)
attr Building_Height = rand (10,15)
@Group ("BUILDING VOLUME")
attr Ground_Floor_Height  = rand (3.5, 4.5)
@Group ("BUILDING VOLUME")
attr Upper_Floor_Height  = rand (3, 3.5)


@Group ("ROOF VOLUME", 1)
@Range ("random", "flat", "hip", "gable", "pyramid")
attr Roof_Form = "random"
const function_Roof_Form = # const is constant. consts are only evaluated once per shape !
 case Roof_Form == "random" :
  30%  : "flat"
  20%  : "hip"
  20%  : "gable"
  else  : "pyramid"
 else : Roof_Form
 

@Group ("ROOF VOLUME")
attr Roof_Height =
 case function_Roof_Form == "flat"  : 0
 else         : rand(2,3)

@Group ("ROOF VOLUME")
attr Overhang = rand (.1,.3)

#################################################################################
### START
#

Lot -->
 case function_Roof_Form == "flat" :
  extrude(world.y, Building_Height - flatRoofBorderHeight)
  Mass
 else :
  extrude(world.y, Building_Height - Roof_Height)
  Mass

#################################################################################
### MASS
#

Mass -->
 # split the 3d volume !
 split(y) {Ground_Floor_Height : FloorVolume("groundFloor") | ~1 : split(y) {~ Upper_Floor_Height : FloorVolume("upperFloor") }* }
 # make a shape copy for the roof
 comp(f) {top : Roof | all : NIL }
 
#################################################################################
### FLOOR VOLUMES
#

FloorVolume(type) -->
 ContinueHere.

#################################################################################
### ROOFS
#

flatRoofBorderHeight = 0.2


Roof -->
 case function_Roof_Form == "flat" :
  offset(-.2)
  comp(f){border : extrude(world.y, flatRoofBorderHeight) RoofColoring | inside : t(0,0,.02) RoofColoring}
 case function_Roof_Form == "hip" :
  roofHip(45)
  s('1,Roof_Height,'1) # scale to the correct height
  RoofColoring
 case function_Roof_Form == "gable" :
  roofGable(45)
  s('1,Roof_Height,'1) # scale to the correct height
  RoofColoring
 else :
  roofPyramid(45)
  s('1,Roof_Height,'1) # scale to the correct height
  RoofColoring


#################################################################################
### COLORING
#

RoofColoring -->
 color(.5,.3,.3)
0 Kudos
12 Replies
MarcoPesci
New Contributor
Hope all is well Daniel,

Could you share the CGA with me? It would be a great help and greatly appreciated!

Thanks! (:
0 Kudos
MarcoPesci
New Contributor
This is a bit like a CGA I have been working on for some typical blocks in Chicago. I use 4 different roof types: flat, corniced, hip, and gable.....and then allow the user to choose one type per block or randomize roof shapes.

Here is what mine look like:
[ATTACH=CONFIG]16365[/ATTACH]

Happy to share the code if anyone wants it.


Could you share the code?
0 Kudos
JonathanMuljono
New Contributor
This is a bit like a CGA I have been working on for some typical blocks in Chicago. I use 4 different roof types: flat, corniced, hip, and gable.....and then allow the user to choose one type per block or randomize roof shapes.

Here is what mine look like:
[ATTACH=CONFIG]16365[/ATTACH]

Happy to share the code if anyone wants it.


Please, I'm looking forward to it. Thanks 🙂
0 Kudos