MBuehler-esristaff

CGA : Simple Roofs

Discussion created by MBuehler-esristaff Employee on Jul 11, 2012
Latest reply on Jun 20, 2017 by CLau-esristaff
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)

Attachments

Outcomes