Пример #1
0
    _offset_dist_ = _offset_dist_ if _offset_dist_ is not None \
        else 0.1 / conversion_to_meters()

    # 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_)

    # get the study points and reverse the sun vectors (for backward ray-tracting)
    rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]
    normals = [from_vector3d(vec) for vec in study_mesh.face_normals]

    # intersect the rays with the mesh
    int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                             points,
                                             rev_vec,
                                             normals,
                                             parallel=parallel_)

    # compute the results
    int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)
    if _timestep_ and _timestep_ != 1:  # divide by the timestep before output
        results = [sum(int_list) / _timestep_ for int_list in int_matrix]
    else:  # no division required
        results = [sum(int_list) for int_list in int_matrix]
            will remain the same. Default: None.
    
    Returns:
        hb_objs: The input _hb_objs that has been moved along the input vector.
"""

ghenv.Component.Name = "HB Move"
ghenv.Component.NickName = 'Move'
ghenv.Component.Message = '1.2.0'
ghenv.Component.Category = 'Honeybee'
ghenv.Component.SubCategory = '0 :: Create'
ghenv.Component.AdditionalHelpFromDocStrings = "6"

try:  # import the ladybug_rhino dependencies
    from ladybug_rhino.togeometry import to_vector3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    hb_objs = [obj.duplicate() for obj in _hb_objs]  # duplicate the initial objects
    vec = to_vector3d(_vector)  # translate the vector to ladybug_geometry
    
    # move all of the objects
    for obj in hb_objs:
        obj.move(vec)
    
    # add the prefix if specified
    if prefix_ is not None:
        for obj in hb_objs:
            obj.add_prefix(prefix_)
except ImportError as e:
    raise ImportError('\nFailed to import ladybug:\n\t{}'.format(e))

try:
    from ladybug_rhino.config import conversion_to_meters
    from ladybug_rhino.togeometry import to_joined_gridded_mesh3d, to_face3d, \
        to_vector3d
    from ladybug_rhino.fromgeometry import from_mesh3d, from_point3d
    from ladybug_rhino.grasshopper import all_required_inputs, hide_output
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
    _height_limit_ = _height_limit_ if _height_limit_ is not None \
        else 100 / conversion_to_meters()

    # convert geometry, objstacles, and vectors to ladybug_geomtery
    study_mesh = to_joined_gridded_mesh3d(_geometry, _grid_size)
    obstacle_faces = [g for geo in _obstacles for g in to_face3d(geo)]
    sun_vectors = [to_vector3d(vec) for vec in _vectors]

    # compute the solar envelope
    solar_obj = SolarEnvelope(
        study_mesh, obstacle_faces, sun_vectors, _height_limit_, solar_rights_)
    lb_mesh = solar_obj.envelope_mesh()
    mesh = from_mesh3d(lb_mesh)
    points = [from_point3d(pt) for pt in lb_mesh.vertices]
    hide_output(ghenv.Component, 1)
Пример #4
0
    from ladybug_rhino.fromgeometry import from_point3d, from_vector3d, from_ray3d, \
        from_polyline3d
    from ladybug_rhino.intersect import join_geometry_to_brep, bounding_box_extents, \
        trace_ray, normal_at_point
    from ladybug_rhino.grasshopper import all_required_inputs, list_to_data_tree, \
        hide_output
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # check the _bounce_count_
    _bounce_count_ = 0 if _bounce_count_ is None else _bounce_count_ - 1
    assert _bounce_count_ >= 0, 'The input _bounce_count_ must be greater '  \
        'than zero. Got {}.'.format(_bounce_count_ + 1)
    # process the input sun vector
    lb_vec = to_vector3d(_vector).normalize()
    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
try:
    from ladybug_rhino.togeometry import to_gridded_mesh3d, to_mesh3d, \
        to_face3d, to_vector3d
    from ladybug_rhino.fromgeometry import from_mesh3d, from_point3d, from_vector3d
    from ladybug_rhino.grasshopper import all_required_inputs
except ImportError as e:
    raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e))

if all_required_inputs(ghenv.Component):
    # check the input and generate the mesh.
    _offset_dist_ = _offset_dist_ or 0
    if quad_only_:  # use Ladybug's built-in meshing methods
        lb_faces = to_face3d(_geometry)
        try:
            x_axis = to_vector3d(quad_only_)
            lb_faces = [
                Face3D(f.boundary, Plane(f.normal, f[0], x_axis), f.holes)
                for f in lb_faces
            ]
        except AttributeError:
            pass  # no plane connected; juse use default orientation
        lb_meshes = [
            geo.mesh_grid(_grid_size, offset=_offset_dist_) for geo in lb_faces
        ]
        if 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
    # set the default origin
    if _origin_ is not None:
        pt = to_point3d(_origin_)
    else:
        pt = []
        for obj in hb_objs:
            origin = obj.center if not isinstance(obj, Model) else Point3D(
                0, 0, 0)
            pt.append(origin)

    # rotate all of the objects
    if _origin_ is None and _axis_ is None:
        for i, obj in enumerate(hb_objs):
            obj.rotate_xy(_angle, pt[i])
    elif _origin_ is not None and _axis_ is None:
        for obj in hb_objs:
            obj.rotate_xy(_angle, pt)
    elif _origin_ is not None and _axis_ is not None:
        _axis_ = to_vector3d(_axis_)
        for obj in hb_objs:
            obj.rotate(_angle, pt, _axis_)
    else:
        _axis_ = to_vector3d(_axis_)
        for i, obj in enumerate(hb_objs):
            obj.rotate(_angle, pt[i], _axis_)

    # add the prefix if specified
    if prefix_ is not None:
        for obj in hb_objs:
            obj.add_prefix(prefix_)