City Engine - create attribute for choosing types of roofs for house

4201
5
Jump to solution
09-02-2014 02:12 AM
IonutAlixandroae
Occasional Contributor

Hello,

 

I want to create a rule for having an attribute in the rule for a house, besides the building`s heights and the roof`s angle, named RoofType and to have the option to choose a type of roof ( Pyramid, Hip, Gable or Shed).

 

Could someone help me with that?

 

Thank you !

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

In your CGA, you will need to use the "case" structure with each of the roof options. Here is an example rule to drop on a polygon shape:

version "2014.0"

@Range(3.5, 5.5)

attr Eave_Height = 4

@Range(15, 45)

attr Roof_Angle = 30

@Range("Pyramid", "Hip", "Gable", "Shed")

attr Roof_Type = "Pyramid"

@StartRule

BuildingFootprint -->

  extrude(Eave_Height)

  comp(f){

    top: color(1,1,0) Roof |

    side: color(1,0,0) Facade

  }

Facade --> YourFacadeCodeHere.

Roof -->

  case Roof_Type == "Pyramid": roofPyramid(Roof_Angle)

  case Roof_Type == "Hip": roofHip(Roof_Angle)

  case Roof_Type == "Gable": roofGable(Roof_Angle)

  else: roofShed(Roof_Angle)

_RoofTime.JPG

View solution in original post

5 Replies
by Anonymous User
Not applicable

In your CGA, you will need to use the "case" structure with each of the roof options. Here is an example rule to drop on a polygon shape:

version "2014.0"

@Range(3.5, 5.5)

attr Eave_Height = 4

@Range(15, 45)

attr Roof_Angle = 30

@Range("Pyramid", "Hip", "Gable", "Shed")

attr Roof_Type = "Pyramid"

@StartRule

BuildingFootprint -->

  extrude(Eave_Height)

  comp(f){

    top: color(1,1,0) Roof |

    side: color(1,0,0) Facade

  }

Facade --> YourFacadeCodeHere.

Roof -->

  case Roof_Type == "Pyramid": roofPyramid(Roof_Angle)

  case Roof_Type == "Hip": roofHip(Roof_Angle)

  case Roof_Type == "Gable": roofGable(Roof_Angle)

  else: roofShed(Roof_Angle)

_RoofTime.JPG

IonutAlixandroae
Occasional Contributor

Thank you very much !!

0 Kudos
IonutAlixandroae
Occasional Contributor

Hello,

What if I have 4 textures in . jpg format and I want them to be added on a specific roof. ( example : for pyramid roof I want 1.jpg, for hip roof the 2.jpg etc etc) and when I change the roof the texture to be changed automatically?

How would the rule be like in this case?

Also, I guess it would be more diversity if the roofs would be created randomly, so I think I need to think how to create a rule for that ( maybe with a case-else % method)?? So when I apply the rule, the houses would have in function of a percentage a random roof and with a specific texture linked to that type of roof...

Thank you !!

0 Kudos
by Anonymous User
Not applicable

Here's a less detailed answer due to the impending arrival of lunch break...

Instead of a new case structure, just use the same case structure as in previous example, but expand the cases. You can put as many operations as you want into each case. So under case =="hip", put texture("2.jpg"), and some combination of these CGA operations in the Help file (F1): 

     - setupProjection

     - projectUV

     - tileUV

     - alignScopeToGeometry - for roofs, try the "any edge / world.lowest" to align to bottom edge of roof.

And you must use comp(f) to get each face of the roof, and apply these to each operations to each roof face.

For randomness try either "stochastic" case function (just search that word in the help file), or use the p() function.

Hope this helps,

Chris

IonutAlixandroae
Occasional Contributor

Thank you very much Chris !!

0 Kudos