Пример #1
0
def xdraw_faces(faces,
                srf=None,
                u=10,
                v=10,
                trim=True,
                tangency=True,
                spacing=0.1,
                flex=1.0,
                pull=1.0):
    """Draw polygonal faces as Breps.
    """
    rg_breps = []
    for f in iter(faces):
        points = f['points']
        corners = [Point3d(*point) for point in points]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]), TOL)
        elif p == 5:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]), TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if not brep:
            continue
        rg_breps.append(brep)
    return rg_breps
Пример #2
0
def xdraw_breps(faces,
                srf=None,
                u=10,
                v=10,
                trim=True,
                tangency=True,
                spacing=0.1,
                flex=1.0,
                pull=1.0,
                **kwargs):
    """Draw polygonal faces as Breps, and optionally set individual name, color,
    and layer properties.
    """
    guids = []
    for f in iter(faces):
        points = f['points']
        name = f.get('name', '')
        color = f.get('color')
        layer = f.get('layer')
        corners = [Point3d(*point) for point in points]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]), TOL)
        elif p == 5:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]), TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if not brep:
            continue
        guid = add_brep(brep)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Пример #3
0
def draw_breps(faces,
               srf=None,
               u=10,
               v=10,
               trim=True,
               tangency=True,
               spacing=0.1,
               flex=1.0,
               pull=1.0,
               **kwargs):
    """Draw polygonal faces as Breps, and optionally set individual name, color,
    and layer properties.

    Parameters
    ----------
    faces : list of dict
        A list of brep dictionaries.
    srf : GUID, optional
        A target surface.
    u : int, optional
        Default is 10.
    v : int, optional
        Default is 10.

    Other Parameters
    ----------------
    trim : bool, optional
    tangency : bool, optional
    spacing : float, optional
    flex : float, optional
    pull : float, optional

    Returns
    -------
    list of GUID

    Notes
    -----
    A brep dict has the following schema:

    .. code-block:: python

        Schema({
            'points': And(list, lambda x: len(x) > 3 and all(len(point) == 3 for point in x),
            Optional('name', default=''): str,
            Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)),
            Optional('layer', default=None): str,
        })

    """
    guids = []
    for f in iter(faces):
        points = f['points']
        name = f.get('name', '')
        color = f.get('color')
        layer = f.get('layer')
        corners = [Point3d(*point) for point in points]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]), TOL)
        elif p == 5:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]), TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if not brep:
            continue
        guid = add_brep(brep)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids
Пример #4
0
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, join=False, **kwargs):
    """Draw polygonal faces as Breps, and optionally set individual name, color,
    and layer properties.

    Parameters
    ----------
    faces : list of dict
        A list of brep dictionaries.
    srf : GUID, optional
        A target surface.
    u : int, optional
        Default is 10.
    v : int, optional
        Default is 10.

    Other Parameters
    ----------------
    trim : bool, optional
    tangency : bool, optional
    spacing : float, optional
    flex : float, optional
    pull : float, optional
    join : bool, optional
        Join the individual faces as polysurfaces. Default is False.

    Returns
    -------
    list of GUID

    Notes
    -----
    A brep dict has the following schema:

    .. code-block:: python

        Schema({
            'points': And(list, lambda x: len(x) > 3 and all(len(point) == 3 for point in x),
            Optional('name', default=''): str,
            Optional('color', default=None): (lambda x: len(x) == 3 and all(0 <= y <= 255 for y in x)),
            Optional('layer', default=None): str,
        })

    Examples
    --------
    Using a compas Mesh as an example:

    >>> from compas.datastructures import Mesh
    >>> from compas.geometry import Box, Frame
    >>> from compas_rhino.utilities import draw_breps
    >>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0)
    >>> mesh = Mesh.from_shape(box)

    Draw convert each mesh face to brep dict schema:

    >>> vertices = mesh.vertices_attributes('xyz')
    >>> breps = [{'points': mesh.face_coordinates(face)} for face in mesh.faces()]

    Draw brep faces as one joined brep.

    >>> guids = draw_breps(breps, join=True)

    """
    breps = []
    for f in iter(faces):
        points = f['points']
        name = f.get('name', '')
        color = f.get('color')
        layer = f.get('layer')
        corners = [Point3d(*point) for point in points + points[:1]]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 3:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               TOL)
        elif p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]),
                                               TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if brep:
            breps.append(brep)

    if join:
        breps = Brep.JoinBreps(breps, TOL)

    guids = []
    for brep in breps:
        guid = add_brep(brep)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids