|
| 1 | +#! python3 |
| 2 | +# venv: brg-csd |
| 3 | +# r: compas_rv>=0.9.5 |
| 4 | + |
| 5 | +import rhinoscriptsyntax as rs # type: ignore |
| 6 | + |
| 7 | +import compas_rhino |
| 8 | +import compas_rhino.conversions |
| 9 | +import compas_rhino.objects |
| 10 | +from compas.datastructures import Mesh |
| 11 | +from compas_rv.session import RVSession |
| 12 | +from compas_tna.envelope import BarrelVaultEnvelope |
| 13 | +from compas_tna.envelope import CrossVaultEnvelope |
| 14 | +from compas_tna.envelope import DomeEnvelope |
| 15 | +from compas_tna.envelope import MeshEnvelope |
| 16 | +from compas_tna.envelope import PavillionVaultEnvelope |
| 17 | +from compas_tna.envelope import PointedVaultEnvelope |
| 18 | + |
| 19 | + |
| 20 | +ENVELOPE_LAYER = "RhinoVAULT::Envelope" |
| 21 | + |
| 22 | + |
| 23 | +def get_location(): |
| 24 | + option = rs.GetString("Envelope location", "Origin", ["Origin", "Coordinates", "Point"]) |
| 25 | + if not option: |
| 26 | + return |
| 27 | + if option == "Origin": |
| 28 | + return 0.0, 0.0 |
| 29 | + if option == "Coordinates": |
| 30 | + x = rs.GetReal("X", 0.0) |
| 31 | + if x is None: |
| 32 | + return |
| 33 | + y = rs.GetReal("Y", 0.0) |
| 34 | + if y is None: |
| 35 | + return |
| 36 | + return x, y |
| 37 | + point = rs.GetPoint("Point") |
| 38 | + if not point: |
| 39 | + return |
| 40 | + return point[0], point[1] |
| 41 | + |
| 42 | + |
| 43 | +def get_size(default_x=10.0, default_y=10.0): |
| 44 | + x_size = rs.GetReal("X size", default_x, minimum=0.0) |
| 45 | + if x_size is None: |
| 46 | + return |
| 47 | + y_size = rs.GetReal("Y size", default_y, minimum=0.0) |
| 48 | + if y_size is None: |
| 49 | + return |
| 50 | + return x_size, y_size |
| 51 | + |
| 52 | + |
| 53 | +def get_thickness(default=0.5): |
| 54 | + return rs.GetReal("Thickness", default, minimum=0.0) |
| 55 | + |
| 56 | + |
| 57 | +def get_crossvault(): |
| 58 | + point = get_location() |
| 59 | + if point is None: |
| 60 | + return |
| 61 | + size = get_size() |
| 62 | + if size is None: |
| 63 | + return |
| 64 | + thickness = get_thickness() |
| 65 | + if thickness is None: |
| 66 | + return |
| 67 | + return CrossVaultEnvelope(x_span=(point[0], point[0] + size[0]), y_span=(point[1], point[1] + size[1]), thickness=thickness) |
| 68 | + |
| 69 | + |
| 70 | +def get_barrelvault(): |
| 71 | + point = get_location() |
| 72 | + if point is None: |
| 73 | + return |
| 74 | + span = rs.GetReal("Span", 10.0, minimum=0.0) |
| 75 | + if span is None: |
| 76 | + return |
| 77 | + depth = rs.GetReal("Depth", 10.0, minimum=0.0) |
| 78 | + if depth is None: |
| 79 | + return |
| 80 | + rise = rs.GetReal("Rise", 3.0, minimum=0.0) |
| 81 | + if rise is None: |
| 82 | + return |
| 83 | + thickness = get_thickness() |
| 84 | + if thickness is None: |
| 85 | + return |
| 86 | + return BarrelVaultEnvelope(rise=rise, span=span, x0=point[0], y_span=(point[1], point[1] + depth), thickness=thickness) |
| 87 | + |
| 88 | + |
| 89 | +def get_pointedvault(): |
| 90 | + point = get_location() |
| 91 | + if point is None: |
| 92 | + return |
| 93 | + size = get_size() |
| 94 | + if size is None: |
| 95 | + return |
| 96 | + minimum_rise = 0.5 * max(size) |
| 97 | + message = "Rise must be greater than or equal to {0:.3f}".format(minimum_rise) |
| 98 | + rise = rs.GetReal(message, minimum_rise, minimum=minimum_rise) |
| 99 | + if rise is None: |
| 100 | + return |
| 101 | + thickness = get_thickness() |
| 102 | + if thickness is None: |
| 103 | + return |
| 104 | + return PointedVaultEnvelope(x_span=(point[0], point[0] + size[0]), y_span=(point[1], point[1] + size[1]), thickness=thickness, hc=rise) |
| 105 | + |
| 106 | + |
| 107 | +def get_pavilionvault(): |
| 108 | + point = get_location() |
| 109 | + if point is None: |
| 110 | + return |
| 111 | + size = get_size() |
| 112 | + if size is None: |
| 113 | + return |
| 114 | + thickness = get_thickness() |
| 115 | + if thickness is None: |
| 116 | + return |
| 117 | + angle = rs.GetReal("Springing angle", 45.0, minimum=0.0, maximum=90.0) |
| 118 | + if angle is None: |
| 119 | + return |
| 120 | + return PavillionVaultEnvelope(x_span=(point[0], point[0] + size[0]), y_span=(point[1], point[1] + size[1]), thickness=thickness, spr_angle=angle) |
| 121 | + |
| 122 | + |
| 123 | +def get_dome(): |
| 124 | + center = get_location() |
| 125 | + if center is None: |
| 126 | + return |
| 127 | + radius = rs.GetReal("Radius", 5.0, minimum=0.0) |
| 128 | + if radius is None: |
| 129 | + return |
| 130 | + thickness = get_thickness() |
| 131 | + if thickness is None: |
| 132 | + return |
| 133 | + r_oculus = rs.GetReal("Oculus radius", 0.5, minimum=0.0) |
| 134 | + if r_oculus is None or r_oculus >= radius: |
| 135 | + return |
| 136 | + return DomeEnvelope(center=center, radius=radius, thickness=thickness, n_hoops=40, n_parallels=40, r_oculus=r_oculus) |
| 137 | + |
| 138 | + |
| 139 | +def get_from_middle(): |
| 140 | + guid = compas_rhino.objects.select_mesh("Select middle mesh") |
| 141 | + if not guid: |
| 142 | + return |
| 143 | + obj = compas_rhino.objects.find_object(guid) |
| 144 | + mesh = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Mesh) |
| 145 | + thickness = get_thickness() |
| 146 | + if thickness is None: |
| 147 | + return |
| 148 | + rs.HideObject(guid) |
| 149 | + return MeshEnvelope.from_middle_mesh(mesh, thickness) |
| 150 | + |
| 151 | + |
| 152 | +def get_from_bounds(): |
| 153 | + guids = [] |
| 154 | + |
| 155 | + guid = compas_rhino.objects.select_mesh("Select intrados") |
| 156 | + rs.UnselectAllObjects() |
| 157 | + if not guid: |
| 158 | + return |
| 159 | + guids.append(guid) |
| 160 | + obj = compas_rhino.objects.find_object(guid) |
| 161 | + intrados = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Mesh) |
| 162 | + |
| 163 | + guid = compas_rhino.objects.select_mesh("Select extrados") |
| 164 | + rs.UnselectAllObjects() |
| 165 | + if not guid: |
| 166 | + return |
| 167 | + guids.append(guid) |
| 168 | + obj = compas_rhino.objects.find_object(guid) |
| 169 | + extrados = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Mesh) |
| 170 | + |
| 171 | + guid = compas_rhino.objects.select_mesh("Select middle (optional)") |
| 172 | + rs.UnselectAllObjects() |
| 173 | + if guid: |
| 174 | + guids.append(guid) |
| 175 | + obj = compas_rhino.objects.find_object(guid) |
| 176 | + middle = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Mesh) |
| 177 | + else: |
| 178 | + middle = None |
| 179 | + |
| 180 | + guid = compas_rhino.objects.select_mesh("Select fill mesh (optional)") |
| 181 | + rs.UnselectAllObjects() |
| 182 | + if guid: |
| 183 | + guids.append(guid) |
| 184 | + obj = compas_rhino.objects.find_object(guid) |
| 185 | + fill = compas_rhino.conversions.mesh_to_compas(obj.Geometry, cls=Mesh) |
| 186 | + else: |
| 187 | + fill = None |
| 188 | + |
| 189 | + rs.HideObjects(guids) |
| 190 | + |
| 191 | + envelope = MeshEnvelope.from_meshes(intrados, extrados, middle) |
| 192 | + if fill: |
| 193 | + envelope.fill = fill |
| 194 | + return envelope |
| 195 | + |
| 196 | + |
| 197 | +LIBRARY = { |
| 198 | + "BarrelVault": get_barrelvault, |
| 199 | + "CrossVault": get_crossvault, |
| 200 | + "PointedVault": get_pointedvault, |
| 201 | + "PavilionVault": get_pavilionvault, |
| 202 | + "Dome": get_dome, |
| 203 | +} |
| 204 | + |
| 205 | + |
| 206 | +def RunCommand(): |
| 207 | + session = RVSession() |
| 208 | + |
| 209 | + option = rs.GetString("Envelope from", "FromLibrary", ["FromLibrary", "FromMiddle", "FromBounds"]) |
| 210 | + if not option: |
| 211 | + return |
| 212 | + |
| 213 | + if option == "FromLibrary": |
| 214 | + pattern = rs.GetString("Envelope pattern", "BarrelVault", list(LIBRARY.keys())) |
| 215 | + if not pattern: |
| 216 | + return |
| 217 | + envelope = LIBRARY[pattern]() |
| 218 | + elif option == "FromMiddle": |
| 219 | + envelope = get_from_middle() |
| 220 | + elif option == "FromBounds": |
| 221 | + envelope = get_from_bounds() |
| 222 | + else: |
| 223 | + return |
| 224 | + |
| 225 | + if not envelope: |
| 226 | + return session.warn("Error creating Envelope. Try again.") |
| 227 | + |
| 228 | + rho = rs.GetInteger("Density masonry (rho)", int(envelope.rho), minimum=0, maximum=200) |
| 229 | + if rho is None: |
| 230 | + return |
| 231 | + envelope.rho = rho |
| 232 | + |
| 233 | + if envelope.fill: |
| 234 | + rho_fill = rs.GetInteger("Density masonry fill (rho_fill)", int(envelope.rho_fill), minimum=0, maximum=200) |
| 235 | + if rho_fill is None: |
| 236 | + return |
| 237 | + envelope.rho_fill = rho_fill |
| 238 | + |
| 239 | + session.clear_envelope(redraw=False) |
| 240 | + session["envelope"] = envelope |
| 241 | + |
| 242 | + settings = session.settings.envelope |
| 243 | + if envelope.intrados: |
| 244 | + session.scene.add(envelope.intrados, disjoint=True, show=settings.show_intrados, name="Intrados", layer=ENVELOPE_LAYER) |
| 245 | + if envelope.middle: |
| 246 | + session.scene.add(envelope.middle, disjoint=True, show=settings.show_middle, name="Middle", layer=ENVELOPE_LAYER) |
| 247 | + if envelope.extrados: |
| 248 | + session.scene.add(envelope.extrados, disjoint=True, show=settings.show_extrados, name="Extrados", layer=ENVELOPE_LAYER) |
| 249 | + if envelope.fill: |
| 250 | + session.scene.add(envelope.fill, disjoint=True, show=settings.show_fill, name="Fill", layer=ENVELOPE_LAYER) |
| 251 | + |
| 252 | + session.scene.redraw() |
| 253 | + rs.Redraw() |
| 254 | + |
| 255 | + print("Envelope successfully created.") |
| 256 | + |
| 257 | + if session.settings.autosave: |
| 258 | + session.record(name="TNO Envelope") |
| 259 | + |
| 260 | + |
| 261 | +if __name__ == "__main__": |
| 262 | + RunCommand() |
0 commit comments