CGA : Simple Roofs

6419
12
07-11-2012 04:51 AM
MatthiasBuehler1
Frequent Contributor II
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
RamliJannatul_Alia
New Contributor
thanks a lot.
0 Kudos
DanielO_Shaughnessy
New Contributor II
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.
MohammadMosum2
New Contributor

Dear Daniel,

i have newly started learning city engine and your CGA could will help me to create my first model but my main problem is to create Dome roof CGA,

Regards#

0 Kudos
CherylLau
Esri Regular Contributor

There is an example of a domed roof on top of the tower in the Sternwarte example.  Help -> Download Tutorials and Examples.

0 Kudos
DevonJenkins
Occasional Contributor
I'd like to take a peak at that roof file CGA please :)
0 Kudos
JoanneO_Brien
Occasional Contributor
Hi

I've been using this roof rule for a while, but I'd like to create some overhang in my roof while maintaining the overall building height, except this rule seems to only apply from the base of the whole roof (including the overhang) so that I get buildings with my walls sticking through the roof (as shown in the image).

This is the Roof code at the moment:
case RoofType == "Gable" : 
    roofGable(roofAngle, gableOverhang, gableOverhang) # roof angle and overhang
    s('1,Roof_Height,'1) # scale to the correct height
    setupProjection(0, scope.xz, roofTexWidth, roofTexHeight)
    texture(rooftile_tex)
    projectUV(0)
    setupProjection(2, scope.xz, scope.sx, scope.sy)#spread across dirtmap
    projectUV(2)
    set(material.dirtmap,roofdirt_tex)

how would I go about modifying it?

thanks! :)
0 Kudos
JoanneO_Brien
Occasional Contributor
Hi

Did you have any thoughts or suggestions for the query above?? :)

Thanks!
0 Kudos
RafałPerzyna
New Contributor
Hi there,

I'm not sure if I get what's your point, but i'll try :)
maybe just try change roofGable parameters?

Try change CGA from Matt
case function_Roof_Form == "gable" :
                roofGable(45)


for

case function_Roof_Form == "gable" :
                roofGable(30,1,1)


first parameter - angle of the roof
second and third- overhang distance
0 Kudos
JoanneO_Brien
Occasional Contributor
Hi

I've already got the overhang's in my code, but they're the ones that cause the issue unfortunately. When extruding a building by the standard height and including this in the roof height as shown in the first post, it all works fine. But when I add an overhang to my roof it counts that extra length when it adds the roof onto the building walls so that the walls are extruded overtop of the roof (ie jutting through the roof instead of just touching or sitting below the roof)

sorry it's quite hard to explain but if you check out the image I posted earlier that shows what I mean...sometimes the walls are very noticable and sometimes they're not depending on the roof angle etc.
0 Kudos