def mask_mesh_from_pattern(base_mask, mask_pattern, color): """Get a Rhino mesh of a mask from a pattern aligned to the faces of a base mesh.""" try: mask_mesh = base_mask.remove_faces_only(mask_pattern) except AssertionError: # all mesh faces have been removed return None mask_mesh.colors = [color] * len(mask_mesh.faces) return from_mesh3d(mask_mesh)
def create_rhino_mesh(_graphic, _lb_mesh): """Copied from Ladybug 'IncidentRadiation' Component Arguments: _graphic: (ladybug.graphic.GraphicContainer) The Laybug Graphic object _lb_mesh: (Ladybug Mesh) A single joined mesh of the entire scene Returns: (tuple) mesh: (_) legend: (_) """ # Create all of the visual outputs _lb_mesh.colors = _graphic.value_colors mesh = from_mesh3d(_lb_mesh) legend = legend_objects(_graphic.legend) return mesh, legend
def build_window_meshes(_window_surface, _grid_size, _mesh_params): """Create the Ladybug Mesh3D grided mesh for the window being analysed Arguments: _window_surface: (Brep) A single window Brep from the scene _grid_size: (float) _mesh_params: (Rhino.Geometry.MeshingParameters) Returns: (tuple) points: (list: Ladybug Point3D) All the analysis points on the window normals: (list: Ladybug Normal) All the normals for the analysis points window_mesh: (ladybug_geometry.geometry3d.Mesh3D) The window window_back_mesh: (ladybug_geometry.geometry3d.Mesh3D) A copy of the window shifted 'back' just a little bit (0.1 units). Used when solving the 'unshaded' situation. """ # create the gridded mesh for the window surface #--------------------------------------------------------------------------- offset_dist = 0.001 window_mesh = to_joined_gridded_mesh3d([_window_surface], _grid_size, offset_dist) window_rh_mesh = from_mesh3d(window_mesh) points = [from_point3d(pt) for pt in window_mesh.face_centroids] # Create a 'back' for the window #--------------------------------------------------------------------------- # Mostly this is done so it can be passed to the ladybug_rhino.intersect.intersect_mesh_rays() # solver as a surfce which is certain to *not* shade the window at all window_back_mesh = None for sr in _window_surface.Surfaces: window_normal = sr.NormalAt(0.5, 0.5) window_normal.Unitize() window_normal = window_normal * -1 * 0.1 window_back = _window_surface.Duplicate() window_back.Translate(window_normal) window_back_mesh = Rhino.Geometry.Mesh.CreateFromBrep( window_back, _mesh_params)[0] normals = [from_vector3d(vec) for vec in window_mesh.face_normals] return points, normals, window_mesh, window_back_mesh, window_rh_mesh
for ival, ang in zip(int_vals, angles)) weight_result = sum(r * w for r, w in zip(w_res, patch_wghts)) results.append(weight_result * 100 / vec_count) else: if patch_wghts: for int_list in int_matrix: weight_result = sum(r * w for r, w in zip(int_list, patch_wghts)) results.append(weight_result * 100 / vec_count) else: results = [ sum(int_list) * 100 / vec_count for int_list in int_matrix ] # create the mesh and legend outputs graphic = GraphicContainer(results, study_mesh.min, study_mesh.max, legend_par_) graphic.legend_parameters.title = '%' if legend_par_ is None or legend_par_.are_colors_default: graphic.legend_parameters.colors = Colorset.view_study() title_txt = vt_str if vt_str in ('Sky Exposure', 'Sky View') else \ '{} View'.format(vt_str) title = text_objects(title_txt, graphic.lower_title_location, graphic.legend_parameters.text_height * 1.5, graphic.legend_parameters.font) # create all of the visual outputs study_mesh.colors = graphic.value_colors mesh = from_mesh3d(study_mesh) legend = legend_objects(graphic.legend)
# generate Ladybug objects for the graphic lb_meshes = [to_mesh3d(mesh) for mesh in _mesh] lb_mesh = Mesh3D.join_meshes(lb_meshes) graphic = GraphicContainer(values, lb_mesh.min, lb_mesh.max, legend_par_, data_type=header.data_type, unit=header.unit) # set titles and set default colors and color ranges if graphic.legend_parameters.are_colors_default: graphic.legend_parameters.colors = colors_from_data_type( header.data_type) if isinstance(header.data_type, TemperatureDelta) and graphic.legend.is_min_default \ and graphic.legend.is_max_default: graphic.legend_parameters.min = -5 graphic.legend_parameters.max = 5 graphic.legend_parameters.title = header.unit global_title = '{}\n{}'.format(header.data_type.name, time_text) title = text_objects(global_title, graphic.lower_title_location, graphic.legend_parameters.text_height * 1.5, graphic.legend_parameters.font) # draw rhino objects lb_mesh.colors = graphic.value_colors mesh = from_mesh3d(lb_mesh) legend = legend_objects(graphic.legend) colors = [color_to_color(col) for col in lb_mesh.colors]
lb_mesh = to_joined_gridded_mesh3d(floor_faces, _grid_size, _dist_floor_) # remove points outside of the room volume if requested if remove_out_: pattern = [ room.geometry.is_point_inside(pt) for pt in lb_mesh.face_centroids ] lb_mesh, vertex_pattern = lb_mesh.remove_faces(pattern) # extract positions and directions from the mesh base_points = [from_point3d(pt) for pt in lb_mesh.face_centroids] base_poss = [(pt.x, pt.y, pt.z) for pt in lb_mesh.face_centroids] base_dirs = [(vec.x, vec.y, vec.z) for vec in lb_mesh.face_normals] # create the sensor grid s_grid = SensorGrid.from_position_and_direction( room.identifier, base_poss, base_dirs) s_grid.display_name = clean_rad_string(room.display_name) s_grid.room_identifier = room.identifier s_grid.mesh = lb_mesh # append everything to the lists grid.append(s_grid) points.append(base_points) mesh.append(from_mesh3d(lb_mesh)) # convert the lists of points to data trees points = list_to_data_tree(points)
def draw_dome(dome_data, center, dome_name, legend_par): """Draw the dome mesh, compass, legend, and title for a sky dome. Args: dome_data: List of radiation values for the dome data center: Point3D for the center of the sun path. dome_name: Text for the dome name, which will appear in the title. legend_par: Legend parameters to be used for the dome Returns: dome_mesh: A colored mesh for the dome based on dome_data. dome_compass: A compass for the dome. dome_legend: A leend for the colored dome mesh. dome_title: A title for the dome. values: A list of radiation values that align with the dome_mesh faces. """ # create the dome mesh and ensure patch values align with mesh faces if len(dome_data) == 145: # tregenza sky lb_mesh = view_sphere.tregenza_dome_mesh_high_res.scale(radius) values = [] # high res dome has 3 x 3 faces per patch; we must convert tot_i = 0 # track the total number of patches converted for patch_i in view_sphere.TREGENZA_PATCHES_PER_ROW: row_vals = [] for val in dome_data[tot_i:tot_i + patch_i]: row_vals.extend([val] * 3) for i in range(3): values.extend(row_vals) tot_i += patch_i values = values + [dome_data[-1] ] * 18 # last patch has triangular faces else: #reinhart sky lb_mesh = view_sphere.reinhart_dome_mesh.scale(radius) values = dome_data + [dome_data[-1] ] * 11 # last patch has triangular faces # move and/or rotate the mesh as needed if north != 0: lb_mesh = lb_mesh.rotate_xy(math.radians(north), Point3D()) if center != Point3D(): lb_mesh = lb_mesh.move(Vector3D(center.x, center.y, center.z)) # project the mesh if requested if projection_ is not None: if projection_.title() == 'Orthographic': pts = (Compass.point3d_to_orthographic(pt) for pt in lb_mesh.vertices) elif projection_.title() == 'Stereographic': pts = (Compass.point3d_to_stereographic(pt, radius, center) for pt in lb_mesh.vertices) else: raise ValueError( 'Projection type "{}" is not recognized.'.format(projection_)) pts3d = tuple(Point3D(pt.x, pt.y, z) for pt in pts) lb_mesh = Mesh3D(pts3d, lb_mesh.faces) # output the dome visualization, including legend and compass move_fac = radius * 0.15 min_pt = lb_mesh.min.move(Vector3D(-move_fac, -move_fac, 0)) max_pt = lb_mesh.max.move(Vector3D(move_fac, move_fac, 0)) graphic = GraphicContainer(values, min_pt, max_pt, legend_par) graphic.legend_parameters.title = 'kWh/m2' lb_mesh.colors = graphic.value_colors dome_mesh = from_mesh3d(lb_mesh) dome_legend = legend_objects(graphic.legend) dome_compass = compass_objects( Compass(radius, Point2D(center.x, center.y), north), z, None, projection_, graphic.legend_parameters.font) # construct a title from the metadata st, end = metadata[2], metadata[3] time_str = '{} - {}'.format(st, end) if st != end else st title_txt = '{} Radiation\n{}\n{}'.format( dome_name, time_str, '\n'.join([dat for dat in metadata[4:]])) dome_title = text_objects(title_txt, graphic.lower_title_location, graphic.legend_parameters.text_height, graphic.legend_parameters.font) return dome_mesh, dome_compass, dome_legend, dome_title, values
from ladybug_geometry.geometry3d.pointvector import Point3D except ImportError as e: raise ImportError('\nFailed to import ladybug_geometry:\n\t{}'.format(e)) try: # import core honeybee dependencies from honeybee.model import Model except ImportError as e: raise ImportError('\nFailed to import honeybee:\n\t{}'.format(e)) try: # import ladybug_rhino dependencies from ladybug_rhino.fromgeometry import from_point3d, from_mesh3d from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) if all_required_inputs(ghenv.Component): assert isinstance(_model, Model), \ 'Expected Honeybee Model. Got {}.'.format(type(_model)) # get the honeybee-radiance objects views = _model.properties.radiance.views grids = _model.properties.radiance.sensor_grids # get the visualizable attributes points = [[from_point3d(Point3D.from_array(s.pos)) for s in sg] for sg in grids] points = list_to_data_tree(points) meshes = [] for grid in grids: if grid.mesh is not None: meshes.append(from_mesh3d(grid.mesh))
pass # no plane connected; juse use default orientation lb_meshes = [] for geo in lb_faces: try: lb_meshes.append(geo.mesh_grid(_grid_size, offset=_offset_dist_)) except AssertionError: # tiny geometry not compatible with quad faces continue if len(lb_meshes) == 0: lb_mesh = None elif len(lb_meshes) == 1: lb_mesh = lb_meshes[0] elif len(lb_meshes) > 1: lb_mesh = Mesh3D.join_meshes(lb_meshes) else: # use Rhino's default meshing try: # assume it's a Rhino Brep lb_mesh = to_gridded_mesh3d(_geometry, _grid_size, _offset_dist_) except TypeError: # assume it's a Rhino Mesh try: lb_mesh = to_mesh3d(_geometry) except TypeError: # unidientified geometry type raise TypeError( '_geometry must be a Brep or a Mesh. Got {}.'.format(type(_geometry))) # generate the test points, vectors, and areas. if lb_mesh is not None: points = [from_point3d(pt) for pt in lb_mesh.face_centroids] vectors = [from_vector3d(vec) for vec in lb_mesh.face_normals] face_areas = lb_mesh.face_areas mesh = [from_mesh3d(lb_mesh)] else: mesh = []
title = [] all_legends = [] all_borders = [] all_labels = [] for i, data_coll in enumerate(_data): try: # sense when several legend parameters are connected lpar = legend_par_[i] except IndexError: lpar = None if len(legend_par_) == 0 else legend_par_[-1] # create the hourly plot object and get the main pieces of geometry hour_plot = HourlyPlot(data_coll, lpar, _base_pt_, _x_dim_, _y_dim_, _z_dim_, reverse_y_) msh = from_mesh2d(hour_plot.colored_mesh2d, _base_pt_.z) if _z_dim_ == 0 else \ from_mesh3d(hour_plot.colored_mesh3d) mesh.append(msh) border = [from_polyline2d(hour_plot.chart_border2d, _base_pt_.z)] + \ [from_linesegment2d(line, _base_pt_.z) for line in hour_plot.hour_lines2d] + \ [from_linesegment2d(line, _base_pt_.z) for line in hour_plot.month_lines2d] all_borders.append(border) legnd = legend_objects(hour_plot.legend) all_legends.append(legnd) tit_txt = text_objects(hour_plot.title_text, hour_plot.lower_title_location, hour_plot.legend_parameters.text_height, hour_plot.legend_parameters.font) title.append(tit_txt) # create the text label objects label1 = [