-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilding_mass.py
161 lines (152 loc) · 5.45 KB
/
building_mass.py
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
161
import geometry_script as gs
# import local modules
import sys
from pathlib import Path
file = Path(__file__).resolve()
parent = file.parents[1]
sys.path.append(str(parent))
from shape_primitives import gs_cube, gs_cylinder, gs_cylinder_scaled, gs_sphere, gs_sphere_scaled
# TODO: add operations for creating more complex shapes
@gs.tree("Building Mass")
def building_mass(bm_type: gs.Int, bm_size: gs.Vector):
"""
Generate a building mass based on the given shape and size.
Note: sphere (2) is not implemented now.
Parameters:
- bm_type (gs.Int): The shape of the building mass. 0 for cube, 1 for cylinder.
- bm_size (gs.Vector): The size of the building mass. Primitives shapes use a unified xyz scale to represent size.
Returns:
- The generated building mass.
- Four curve line Geometries representing the four sides of the building mass. position at the center of the bottom floor.
"""
# use compare to determine shape type: currently switch nodes can have T/F outputs only, so 3 types need 2 compares (cube?cylinder?sphere)
is_cube = gs.compare(
operation=gs.Compare.Operation.EQUAL,
data_type=gs.Compare.DataType.INT,
a=bm_type,
b=0,
)
is_cylinder = gs.compare(
operation=gs.Compare.Operation.EQUAL,
data_type=gs.Compare.DataType.INT,
a=bm_type,
b=1,
)
cube = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cube,
false=None,
true=gs_cube(size=bm_size),
)
# edges
cube_line_positive_x = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cube,
false=None,
true=gs.curve_line(
start=gs.combine_xyz(x=bm_size.x / 2, y=-bm_size.y / 2, z=-bm_size.z / 2),
end=gs.combine_xyz(x=bm_size.x / 2, y=bm_size.y / 2, z=-bm_size.z / 2),
),
)
cube_line_positive_y = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cube,
false=None,
true=gs.curve_line(
start=gs.combine_xyz(x=bm_size.x / 2, y=bm_size.y / 2, z=-bm_size.z / 2),
end=gs.combine_xyz(x=-bm_size.x / 2, y=bm_size.y / 2, z=-bm_size.z / 2),
),
)
cube_line_negative_x = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cube,
false=None,
true=gs.curve_line(
start=gs.combine_xyz(x=-bm_size.x / 2, y=bm_size.y / 2, z=-bm_size.z / 2),
end=gs.combine_xyz(x=-bm_size.x / 2, y=-bm_size.y / 2, z=-bm_size.z / 2),
),
)
cube_line_negative_y = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cube,
false=None,
true=gs.curve_line(
start=gs.combine_xyz(x=-bm_size.x / 2, y=-bm_size.y / 2, z=-bm_size.z / 2),
end=gs.combine_xyz(x=bm_size.x / 2, y=-bm_size.y / 2, z=-bm_size.z / 2),
),
)
depth = bm_size.z
cylinder = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cylinder,
false=None,
true=gs_cylinder_scaled(size=bm_size),
)
nighty_degree = gs.math(operation=gs.Math.Operation.RADIANS, value=90)
deg_45 = gs.math(operation=gs.Math.Operation.RADIANS, value=45)
deg_135 = gs.math(operation=gs.Math.Operation.RADIANS, value=135)
deg_225 = gs.math(operation=gs.Math.Operation.RADIANS, value=225)
cylinder_line_positive_x = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cylinder,
false=None,
true=gs.arc(
radius=0.5,
start_angle=-deg_45,
sweep_angle=nighty_degree
).transform(
translation=gs.combine_xyz(x=0, y=0, z=-depth / 2),
scale=bm_size)
)
cylinder_line_positive_y = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cylinder,
false=None,
true=gs.arc(
radius=0.5,
start_angle=deg_45,
sweep_angle=nighty_degree
).transform(
translation=gs.combine_xyz(x=0, y=0, z=-depth / 2),
scale=bm_size)
)
cylinder_line_negative_x = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cylinder,
false=None,
true=gs.arc(
radius=0.5,
start_angle=deg_135,
sweep_angle=nighty_degree
).transform(
translation=gs.combine_xyz(x=0, y=0, z=-depth / 2),
scale=bm_size)
)
cylinder_line_negative_y = gs.switch(
input_type=gs.Switch.InputType.GEOMETRY,
switch=is_cylinder,
false=None,
true=gs.arc(
radius=0.5,
start_angle=deg_225,
sweep_angle=nighty_degree
).transform(
translation=gs.combine_xyz(x=0, y=0, z=-depth / 2),
scale=bm_size)
)
bm_shape = gs.mesh_boolean(
operation=gs.MeshBoolean.Operation.UNION, mesh_2=[cube, cylinder]
)
line_positive_x = gs.join_geometry(
geometry=[cube_line_positive_x, cylinder_line_positive_x]
)
line_positive_y = gs.join_geometry(
geometry=[cube_line_positive_y, cylinder_line_positive_y]
)
line_negative_x = gs.join_geometry(
geometry=[cube_line_negative_x, cylinder_line_negative_x]
)
line_negative_y = gs.join_geometry(
geometry=[cube_line_negative_y, cylinder_line_negative_y]
)
return bm_shape, line_positive_x, line_positive_y, line_negative_x, line_negative_y