Beispiel #1
0
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
Beispiel #2
0
    '2': 'Spherical',
    '3': 'Sky Exposure',
    '4': 'Sky View'
}

if all_required_inputs(ghenv.Component) and _run:
    # process the view_type_ and set the default values
    vt_str = VIEW_TYPES[_view_type]
    _resolution_ = _resolution_ if _resolution_ is not None else 1
    _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
        else 0.1 / conversion_to_meters()
    if _geo_block_ is None:
        _geo_block_ = True if vt_str in ('Sky Exposure', 'Sky View') else False

    # create the gridded mesh from the geometry
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size, _offset_dist_)
    points = [from_point3d(pt) for pt in study_mesh.face_centroids]
    hide_output(ghenv.Component, 1)

    # get the view vectors based on the view type
    patch_wghts = None
    if vt_str == 'Horizontal Radial':
        lb_vecs = view_sphere.horizontal_radial_vectors(30 * _resolution_)
    elif vt_str == 'Horizontal 30-Degree Offset':
        patch_mesh, lb_vecs = view_sphere.horizontal_radial_patches(
            30, _resolution_)
        patch_wghts = view_sphere.horizontal_radial_patch_weights(
            30, _resolution_)
    elif vt_str == 'Spherical':
        patch_mesh, lb_vecs = view_sphere.sphere_patches(_resolution_)
        patch_wghts = view_sphere.sphere_patch_weights(_resolution_)
    from ladybug_rhino.text import text_objects
    from ladybug_rhino.intersect import join_geometry_to_mesh, intersect_mesh_rays
    from ladybug_rhino.grasshopper import all_required_inputs, hide_output, \
        show_output, objectify_output, de_objectify_output, recommended_processor_count
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component) and _run:
    # set the default offset distance and _cpu_count
    _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
        else 0.1 / conversion_to_meters()
    workers = _cpu_count_ if _cpu_count_ is not None else recommended_processor_count(
    )

    # create the gridded mesh from the geometry
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
    points = [
        from_point3d(pt.move(vec * _offset_dist_))
        for pt, vec in zip(study_mesh.face_centroids, study_mesh.face_normals)
    ]
    hide_output(ghenv.Component, 1)

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_)

    # deconstruct the matrix and get the sky dome vectors
    mtx = de_objectify_output(_sky_mtx)
    total_sky_rad = [
        dir_rad + dif_rad for dir_rad, dif_rad in zip(mtx[1], mtx[2])
    ]
    ground_rad = [(sum(total_sky_rad) / len(total_sky_rad)) * mtx[0][1]
Beispiel #4
0
    neg_lb_vec = -lb_vec
    vec = from_vector3d(lb_vec)

    # convert all of the _source_geo and contex into a single Brep for ray tracing
    rtrace_brep = join_geometry_to_brep(_source_geo + context_)

    # autocompute the first and last bounce length if it's unspecified
    if _first_length_ is None or _last_length_ is None:
        max_pt, min_pt = (to_point3d(p)
                          for p in bounding_box_extents(rtrace_brep))
        diag_dist = max_pt.distance_to_point(min_pt)
        _first_length_ = diag_dist if _first_length_ is None else _first_length_
        _last_length_ = diag_dist if _last_length_ is None else _last_length_

    # create the gridded mesh from the _source_geo and set up the starting rays
    study_mesh = to_joined_gridded_mesh3d(_source_geo, _grid_size)
    move_vec = neg_lb_vec * _first_length_
    source_points = [pt + move_vec for pt in study_mesh.face_centroids]
    lb_rays = [Ray3D(pt, lb_vec) for pt in source_points]
    start_rays = [from_ray3d(ray) for ray in lb_rays]

    # trace each ray through the geometry
    cutoff_ang = math.pi / 2
    rtrace_geo = [rtrace_brep]
    rays, int_pts = [], []
    for ray, pt, norm in zip(start_rays, source_points,
                             study_mesh.face_normals):
        if norm.angle(neg_lb_vec) < cutoff_ang:
            pl_pts = trace_ray(ray, rtrace_geo, _bounce_count_ + 1)
            # if the intersection was successful, create a polyline represeting the ray
            if pl_pts:
Beispiel #5
0
    # create lists to be filled with content
    grid = []
    points = []
    mesh = []

    for room in _rooms:
        # get all of the floor faces of the room as Breps
        floor_faces = [
            from_face3d(face.geometry.flip()) for face in room.faces
            if isinstance(face.type, Floor)
        ]

        if len(floor_faces) != 0:
            # create the gridded ladybug Mesh3D
            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