/** * File: building.cga * Created: 3 Nov 2013 21:51:27 GMT * Author: Michal Soucha * * Inspired in CGA tutorials */ version "2011.2" @Range(LOD0=0,LOD1=1) attr LOD = 1 @Range(10,50) attr height = rand(10,20) @Range(3,4.5) attr groundFloorHeight = 3.2 @Range(2,4) attr floorHeight = 2.5 @Range(1.5,3) attr entranceWidth = 2.3 @Range(2.5,3) attr tileWidth = 3 attr bgColor = "#ffffff" const window_asset = "facades/elem.window.frame.obj" const halfarc_asset = "facades/arc_thin.obj" const modillion_asset = "facades/ledge_modillion.03.for_cornice_ledge_closed.lod0.obj" const roof_front_side_asset = "facades/RoofFrontSide.obj" const window_sill_asset = "facades/WindowSill.obj" const tympanum_asset = "facades/Tympanum.obj" const ledge_asset = "facades/ledge.03.twopart_lessprojection.obj" const round_wintop_asset = "facades/round_windowtop.obj" const tri_wintop_asset = "facades/triangle_windowtop.obj" const round2_wintop_asset = "facades/round2_windowtop.obj" const barok_wintop_asset = "facades/barok_windowtop.obj" const dirt_tex = "facades/textures/dirtmap.15.tif" randomWindowTex = fileRandom("*facades/textures/window.*.jpg") randomDoorTex = fileRandom("*facades/textures/Door.*.jpg") randomDoorTopTex = fileRandom("*facades/textures/DoorTop.*.jpg") const cornerWallWidth = 0.5 const windowSideWallWidth = 0.5 const groundSideWallWidth = 0.5 const groundLedge = 0.4 const atticLedge = 0.3 const doorHeight = 2.2 atticFloorHeight = 0.8*floorHeight Lot --> extrude(height) Building Building --> comp(f) { front : FrontFacade | side : SideFacade | top : split(y) { 0.4: TopFront | Roof } } Roof --> roofGable(atan(floorHeight/(scope.sx/2)),0,0,true,0) color("#7f3439") setupProjection(2, scope.xy, scope.sx, scope.sy) set(material.dirtmap, dirt_tex) projectUV(2) TopFront --> split(x) { ~scope.sx/2 : RoofOrnament(0) | 1.5*entranceWidth : RoofMiddle | ~scope.sx/2 : RoofOrnament(1) } RoofOrnament(side) --> r(90,0,case side == 1: 180 else : 0) t('-side, 0, 0) s('1,atticFloorHeight,0.45) center(z) setupProjection(2, scope.xy, scope.sx, scope.sy) setupProjection(0, scope.xy, scope.sx, scope.sy) set(material.specular.r, 0) set(material.specular.g, 0) set(material.specular.b, 0) [i(roof_front_side_asset) Wall(2)] RoofMiddle --> extrude(atticFloorHeight) comp(f) { front : split(y) { 0.7*atticFloorHeight : Attic | 0.3*atticFloorHeight : AtticBorder(2) } | top : FrontRoof | all : Wall(0) } FrontRoof --> r(90,0,0) s('1.018,'1.3,0.55) center(x) t(0,0,-.45) setupProjection(2, scope.xy, scope.sx, scope.sy) setupProjection(0, scope.xy, scope.sx, scope.sy) set(material.specular.r, 0) set(material.specular.g, 0) set(material.specular.b, 0) [i(tympanum_asset) Wall(2)] Attic --> setupProjection(2, scope.xy, scope.sx, scope.sy) split(x) { scope.sx/4 : AtticBorder(1) | scope.sx/4 : AtticWindow | scope.sx/4 : AtticWindow | scope.sx/4 : AtticBorder(1) } AtticWindow --> case LOD > 0 : s('1,'1,0.3) t(0,0,-0.25) [i(window_asset) AtticGlass] AtticGlass else: AtticGlass AtticGlass --> setupProjection(0,scope.xy, '1, '1) texture("facades/textures/AtticWindow.jpg") projectUV(0) Wall(0) AtticBorder(isVertical) --> setupProjection(0,scope.xy,scope.sx,scope.sy) texture("facades/textures/AtticBorder."+isVertical+".jpg") projectUV(0) Wall(0) // sides SideFacade --> setupProjection(0, scope.xy, .5, 2) setupProjection(2, scope.xy, scope.sx, scope.sy) Wall(2) // front FrontFacade --> setupProjection(0, scope.xy, .5, 2) setupProjection(2, scope.xy, scope.sx, scope.sy) split(x) { cornerWallWidth : CornerWall | {~tileWidth : Column(0)}* | entranceWidth : Column(1) | {~tileWidth : Column(0)}* | cornerWallWidth : CornerWall } CornerWall --> split(y) { groundFloorHeight : Wall(1) | ~groundLedge : Ledge(0) | {~floorHeight : Wall(2)}* | ~atticLedge : Ledge(-1) | ~floorHeight : Wall(2) | ~atticLedge : Ledge(-2) } Column(isEntrance) --> split(y) { groundFloorHeight : GroundTile(isEntrance) | ~groundLedge : Ledge(isEntrance) | {~floorHeight : Tile(split.index, isEntrance)}* | ~atticLedge : Ledge(-1) | ~floorHeight : Tile(999, isEntrance) | ~atticLedge : Ledge(-2) } GroundTile(isEntrance) --> split(x) { ~groundSideWallWidth : SolidWall | split(y) { ~doorHeight : Door(isEntrance) | scope.sx/2 : Arcs(isEntrance) | 0.5 : Arctop(isEntrance) } | ~groundSideWallWidth : SolidWall } Door(isEntrance) --> case LOD > 0 : s('1,'1,0.1) t(0,0,-0.5) texture( case (isEntrance == 1) : "facades/textures/Entrance.jpg" else : randomDoorTex) i("builtin:cube") else : setupProjection(0,scope.xy,scope.sx,scope.sy) texture( case (isEntrance == 1) : "facades/textures/Entrance.jpg" else : randomDoorTex) projectUV(0) # Adds wall material and a centered modillion Arctop(isEntrance) --> case isEntrance == 1 && LOD > 0 : Wall(1) s(0.5,'1,0.3) center(x) i(modillion_asset) Wall(1) else : Wall(1) # Arcs(isEntrance) --> case LOD > 0 : s('1,'1,0.4) t(0,0,-0.4) DoorTop(isEntrance) i("builtin:cube") split(x){ ~1 : ArcAsset | ~1 : r(0,0,-90) t('-1,0,0) ArcAsset} else : DoorTop(isEntrance) # inserts the actual arc asset ArcAsset --> i(halfarc_asset) Wall(1) DoorTop(isEntrance) --> setupProjection(0, scope.xy, '1, '1) texture(case (isEntrance == 1) : "facades/textures/EntranceTop.jpg" else : randomDoorTopTex) projectUV(0) Ledge(type) --> case LOD > 0 : case type == 0 :// groundFloor i(ledge_asset) s('1,'1.3,0.25) Wall(2) case type == 1 :// groundFloor above entrance i(ledge_asset) s('1,'1.5,0.3) Wall(2) case type == -1 :// below attic i(ledge_asset) s('1,'1.5,0.2) Wall(2) case type == -2 :// above attic i(ledge_asset) s('1,'1,0.3) Wall(2) case type > 2 && type < 999 :// window sill i(window_sill_asset) s('1,'1,0.1) Wall(2) else : Wall(2) else : Wall(2) Tile(floorIdx, aboveEntrance) --> split(x) { windowSideWallWidth : Wall(2) | split(y) { ~0.05*floorHeight : Ledge(floorIdx) | ~0.65*floorHeight : [case aboveEntrance == 1 : Window else : split(x) {Window | Window}] | ~0.3*floorHeight : WindowOrnament(floorIdx, aboveEntrance) } | windowSideWallWidth : Wall(2) } Window --> case LOD > 0 : s('1,'1,0.3) t(0,0,-0.25) [i(window_asset) Wall(2)] Glass else: Glass Glass --> setupProjection(0,scope.xy, '1, '1) projectUV(0) texture(randomWindowTex) //set(material.specular.r, 1) set(material.specular.g, 1) set(material.specular.b, 1) set(material.shininess, 4) WindowOrnament(floorIdx, aboveEntrance) --> case LOD > 0 : case floorIdx == 0: [case aboveEntrance == 1: [i(barok_wintop_asset) Wall(2)] Wall(2) else : [i(round_wintop_asset) Wall(2)] Wall(2)] case floorIdx == 2: [case aboveEntrance == 1: [i(barok_wintop_asset) Wall(2)] Wall(2) else : [i(round_wintop_asset) Wall(2)] Wall(2)] case floorIdx == 999: [case aboveEntrance == 1: [i(round2_wintop_asset) Wall(2)] Wall(2) else : [i(round_wintop_asset) Wall(2)] Wall(2)] else : [i(tri_wintop_asset) Wall(2)] Wall(2) else : Wall(2) Wall(walltype) --> case walltype > 0 : color(bgColor) texture("facades/textures/Wall."+walltype+".jpg") set(material.dirtmap, dirt_tex) projectUV(0) projectUV(2) // dirt only else : color(bgColor) set(material.dirtmap, dirt_tex) projectUV(2) SolidWall --> case LOD > 0 : s('1,'1,.4) t(0,0,-.4) i("builtin:cube:notex") Wall(1) else : Wall(1)