forked from jbdong/CityEngine_cga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleBuilding.03.cga
160 lines (122 loc) · 4.01 KB
/
simpleBuilding.03.cga
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* File: simpleBuilding.03.cga
* Created: 4 May 2008 23:27:29 GMT
* Author: andi
*/
version "2010.3"
/* Attributes *************************************/
attr groundfloor_height = 4
attr floor_height = 3.5
attr tile_width = 3
attr height = 11
attr wallColor = "#fefefe"
attr LOD = 1
/* Assets *************************************/
// geometries
window_asset = "facades/window.obj"
// textures
frontdoor_tex = "facades/textures/shopdoor.tif"
wall_tex = "facades/textures/brickwall2.tif"
dirt_tex = "facades/textures/dirtmap.15.tif"
roof_tex = "roofs/roof.tif"
# this function will get one of the 9 window textures in the assets folder
randomWindowTexture = fileRandom("*facades/textures/window.*.tif")
/* Initial Shape starting rule *************/
# scale the lit to leave a small border and extrude the lot to building height
Lot -->
extrude(height) Building
# inner lots are dropped
LotInner --> NIL
# split the building geometry into its facade components
Building -->
comp(f) { front : Frontfacade | side : Sidefacade | top: Roof}
# the front facade is subdivided into one front groundfloor
# and upper floors
Frontfacade -->
setupProjection(0, scope.xy, 1.5, 1, 1) # setup 1.5m x 1m texture tiles along scopes xy plane (and distortion in z)
setupProjection(2, scope.xy, scope.sx, scope.sy)
split(y){ groundfloor_height : Groundfloor
| {~floor_height : Floor}* }
# a side facade is subdivided into one bottom floor
# and upper floors.
Sidefacade -->
setupProjection(0, scope.xy, 1.5, 1, 1) # setup 1.5m x 1m texture tiles along scopes xy plane (and distortion in z)
setupProjection(2, scope.xy, scope.sx, scope.sy)
split(y){ groundfloor_height : Floor
| {~floor_height : Floor}* }
# a roof texture is applied to the roof face
Roof -->
setupProjection(0, scope.xy, scope.sx, scope.sy)
texture(roof_tex)
projectUV(0)
# each floor is horizontally split into two narrow corner areas on
# each side of the floor, and into a set of window tiles in between
Floor -->
split(x){ 1 : Wall
| { ~tile_width : Tile }*
| 1 : Wall }
# similarily, the front groundfloor is horizontally split into
# two narrow corner areas on each side of the floor,
# a special entrance tile on the right
# and into a set of window tiles in between
Groundfloor -->
split(x){ 1 : Wall
| { ~tile_width : Tile }*
| ~tile_width : EntranceTile
| 1 : Wall }
# a tile consists of a centered window element and
# wall elements above, below, left and right
Tile -->
split(x){ ~1 : Wall
| 2 : split(y){ 1: Wall | 1.5: Window | ~1: Wall }
| ~1 : Wall }
# similarily, the EntranceTile contains a centered Door element,
# but with no wall on spacing below
EntranceTile -->
split(x){ ~1 : SolidWall
| 2 : split(y){ 2.5: Door | ~2: SolidWall }
| ~1 : SolidWall }
# firstly, the depth and the depth position of the future window is set
# secondly, one of nine window textures is randomly selected
# finally, the window geometry asset is inserted
Window -->
case LOD > 0 :
s('1,'1,0.4)
t(0,0,-0.25)
texture(randomWindowTexture)
i(window_asset)
else :
setupProjection(0,scope.xy,scope.sx,scope.sy)
texture(randomWindowTexture)
projectUV(0)
# same for the door asset. Scaling, positioning, texture selection
# and geometry insert
# TODO: fix door uv bug (problem with uv handling on split?)
Door -->
case LOD > 0 :
s('1,'1,0.1)
t(0,0,-0.5)
texture(frontdoor_tex)
i("builtin:cube")
else :
setupProjection(0,scope.xy,scope.sx,scope.sy)
texture(frontdoor_tex)
projectUV(0)
# for the wall asset, setting the texture scale params u and v
# guarantees a texture mapping that nicely fits over the whole facade
Wall -->
color(wallColor)
texture(wall_tex)
set(material.dirtmap, dirt_tex)
projectUV(0) projectUV(2)
SolidWall -->
case LOD > 0 :
color(wallColor)
s('1,'1,0.4)
t(0,0,-0.4)
texture(wall_tex)
set(material.dirtmap, dirt_tex)
i("builtin:cube:notex")
projectUV(0) projectUV(2)
else :
Wall