Пример #1
0
def draw_mesh(vertices, faces, name=None, color=None, disjoint=False, **kwargs):
    points = []
    mesh = RhinoMesh()
    if disjoint:
        for keys in faces:
            i = len(points)
            facet = [j + i for j in range(len(keys))]
            for key in keys:
                point = vertices[key]
                points.append(point)
                x, y, z = point
                mesh.Vertices.Add(x, y, z)
            mesh.Faces.AddFace(*facet)
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            mesh.Faces.AddFace(*face)
    mesh.Normals.ComputeNormals()
    mesh.Compact()
    guid = add_mesh(mesh)
    if guid:
        obj = find_object(guid)
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if name:
            attr.Name = name
        obj.CommitChanges()
    return guid
Пример #2
0
def draw_mesh(vertices,
              faces,
              name=None,
              color=None,
              disjoint=False,
              **kwargs):
    """Draw a mesh and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    vertices : :obj:`list` of point
        A list of point locations.
    faces : :obj:`list` of :obj:`list` of :obj:`int`
        A list of faces as lists of indices into ``vertices``.
    name : :obj:`str`, optional
    color : RGB :obj:`tuple`, optional
    disjoint : :obj:`bool`, optional
        Draw the mesh with disjoint faces.
        Default is ``False``.

    Returns
    -------
    str or GUID

    """
    points = []
    mesh = RhinoMesh()
    if disjoint:
        for keys in faces:
            i = len(points)
            facet = [j + i for j in range(len(keys))]
            for key in keys:
                point = vertices[key]
                points.append(point)
                x, y, z = point
                mesh.Vertices.Add(x, y, z)
            mesh.Faces.AddFace(*facet)
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            mesh.Faces.AddFace(*face)
    mesh.Normals.ComputeNormals()
    mesh.Compact()
    guid = add_mesh(mesh)
    if guid:
        obj = find_object(guid)
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if name:
            attr.Name = name
        obj.CommitChanges()
    return guid
Пример #3
0
def mesh_from_dict(data):
    mesh = Mesh()

    for vl in data["vertices"]:
        mesh.Vertices.Add(vl[0], vl[1], vl[2])

    for fl in data["faces"]:
        if len(fl) == 3:
            mesh.Faces.AddFace(fl[0], fl[1], fl[2])
        else:
            mesh.Faces.AddFace(fl[0], fl[1], fl[2], fl[3])

    mesh.RebuildNormals()

    return mesh
Пример #4
0
def draw_mesh(vertices, faces, color=None, vertex_normals=None, texture_coordinates=None):
    """Draw mesh in Grasshopper.
    """
    mesh = Mesh()
    for a, b, c in vertices:
        mesh.Vertices.Add(a, b, c)
    for face in faces:
        if len(face) < 4:
            mesh.Faces.AddFace(face[0], face[1], face[2])
        else:
            mesh.Faces.AddFace(face[0], face[1], face[2], face[3])

    if vertex_normals:
        count = len(vertex_normals)
        normals = CreateInstance(Vector3f, count)
        for i, normal in enumerate(vertex_normals):
            normals[i] = Vector3f(normal[0], normal[1], normal[2])
        mesh.Normals.SetNormals(normals)

    if texture_coordinates:
        count = len(texture_coordinates)
        tcs = CreateInstance(Point2f, count)
        for i, tc in enumerate(texture_coordinates):
            tcs[i] = Point2f(tc[0], tc[1])
        mesh.TextureCoordinates.SetTextureCoordinates(tcs)

    if color:
        count = len(vertices)
        colors = CreateInstance(Color, count)
        for i in range(count):
            colors[i] = rs.coercecolor(color)
        mesh.VertexColors.SetColors(colors)

    return mesh
Пример #5
0
def draw_mesh(vertices,
              faces,
              color=None,
              vertex_normals=None,
              texture_coordinates=None):
    """Draw mesh in Grasshopper.

    Parameters
    ----------
    vertices : list of point
        List of vertex locations.
    faces : list of list of int
        List of faces defined as lists of indices into the list of vertices.

    Other Parameters
    ----------------
    color : tuple, list or :class:`System.Drawing.Color`, optional
    vertex_normals : bool, optional
    texture_coordinates

    Returns
    -------
    list of :class:`Rhino.Geometry.Mesh`

    """
    mesh = Mesh()
    for a, b, c in vertices:
        mesh.Vertices.Add(a, b, c)
    for face in faces:
        if len(face) < 4:
            mesh.Faces.AddFace(face[0], face[1], face[2])
        else:
            mesh.Faces.AddFace(face[0], face[1], face[2], face[3])

    if vertex_normals:
        count = len(vertex_normals)
        normals = CreateInstance(Vector3f, count)
        for i, normal in enumerate(vertex_normals):
            normals[i] = Vector3f(normal[0], normal[1], normal[2])
        mesh.Normals.SetNormals(normals)

    if texture_coordinates:
        count = len(texture_coordinates)
        tcs = CreateInstance(Point2f, count)
        for i, tc in enumerate(texture_coordinates):
            tcs[i] = Point2f(tc[0], tc[1])
        mesh.TextureCoordinates.SetTextureCoordinates(tcs)

    if color:
        count = len(vertices)
        colors = CreateInstance(Color, count)
        for i in range(count):
            colors[i] = rs.coercecolor(color)
        mesh.VertexColors.SetColors(colors)

    return mesh
Пример #6
0
def xdraw_mesh(vertices,
               faces,
               vertex_normals=None,
               texture_coordinates=None,
               vertex_colors=None):
    """Draw mesh.
    """
    # TODO: This should move to compas/compas_grasshoper/utilities/drawing.py.
    # TODO: This function is mainly a copy of rhinoscriptsyntax.AddMesh, just without scriptcontext adding.

    mesh = Mesh()
    for a, b, c in vertices:
        mesh.Vertices.Add(a, b, c)
    for face in faces:
        if len(face) < 4:
            mesh.Faces.AddFace(face[0], face[1], face[2])
        else:
            mesh.Faces.AddFace(face[0], face[1], face[2], face[3])

    if vertex_normals:
        count = len(vertex_normals)
        normals = CreateInstance(Vector3f, count)
        for i, normal in enumerate(vertex_normals):
            normals[i] = Vector3f(normal[0], normal[1], normal[2])
        mesh.Normals.SetNormals(normals)

    if texture_coordinates:
        count = len(texture_coordinates)
        tcs = CreateInstance(Point2f, count)
        for i, tc in enumerate(texture_coordinates):
            tcs[i] = Point2f(tc[0], tc[1])
        mesh.TextureCoordinates.SetTextureCoordinates(tcs)

    if vertex_colors:
        for i, color in vertex_colors.iteritems():
            color = rs.coercecolor(color)
            mesh.VertexColors.SetColor(i, color)

    return mesh
Пример #7
0
def draw_mesh(vertices,
              faces,
              name=None,
              color=None,
              disjoint=False,
              **kwargs):
    """Draw a mesh and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    vertices : :obj:`list` of point
        A list of point locations.
    faces : :obj:`list` of :obj:`list` of :obj:`int`
        A list of faces as lists of indices into ``vertices``.
    name : :obj:`str`, optional
    color : RGB :obj:`tuple`, optional
    disjoint : :obj:`bool`, optional
        Draw the mesh with disjoint faces.
        Default is ``False``.

    Returns
    -------
    str or GUID

    """
    mesh = RhinoMesh()
    if disjoint:
        P = 0
        for face in faces:
            f = len(face)
            if f == 3:
                mesh.Vertices.Add(*vertices[face[0]])
                mesh.Vertices.Add(*vertices[face[1]])
                mesh.Vertices.Add(*vertices[face[2]])
                mesh.Faces.AddFace(P + 0, P + 1, P + 2)
                P += 3
            elif f == 4:
                mesh.Vertices.Add(*vertices[face[0]])
                mesh.Vertices.Add(*vertices[face[1]])
                mesh.Vertices.Add(*vertices[face[2]])
                mesh.Vertices.Add(*vertices[face[3]])
                mesh.Faces.AddFace(P + 0, P + 1, P + 2, P + 3)
                P += 4
            else:
                continue
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            mesh.Faces.AddFace(*face)
    mesh.Normals.ComputeNormals()
    mesh.Compact()
    guid = add_mesh(mesh)
    if guid:
        obj = find_object(guid)
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if name:
            attr.Name = name
        obj.CommitChanges()
    return guid
Пример #8
0
def draw_mesh(vertices, faces, name=None, color=None, disjoint=False, **kwargs):
    """Draw a mesh and optionally set individual name, color, and layer properties.

    Parameters
    ----------
    vertices : :obj:`list` of point
        A list of point locations.
    faces : :obj:`list` of :obj:`list` of :obj:`int`
        A list of faces as lists of indices into ``vertices``.
    name : :obj:`str`, optional
    color : RGB :obj:`tuple`, optional
    disjoint : :obj:`bool`, optional
        Draw the mesh with disjoint faces.
        Default is ``False``.

    Returns
    -------
    str or GUID

    """
    mesh = RhinoMesh()
    if disjoint:
        for face in faces:
            f = len(face)
            if f < 3:
                continue
            if f == 3:
                a = mesh.Vertices.Add(* vertices[face[0]])
                b = mesh.Vertices.Add(* vertices[face[1]])
                c = mesh.Vertices.Add(* vertices[face[2]])
                mesh.Faces.AddFace(a, b, c)
            elif f == 4:
                a = mesh.Vertices.Add(* vertices[face[0]])
                b = mesh.Vertices.Add(* vertices[face[1]])
                c = mesh.Vertices.Add(* vertices[face[2]])
                d = mesh.Vertices.Add(* vertices[face[3]])
                mesh.Faces.AddFace(a, b, c, d)
            else:
                if MeshNgon:
                    points = [vertices[vertex] for vertex in face]
                    centroid = centroid_polygon(points)
                    indices = []
                    for point in points:
                        indices.append(mesh.Vertices.Add(* point))
                    c = mesh.Vertices.Add(* centroid)
                    facets = []
                    for i, j in pairwise(indices + indices[:1]):
                        facets.append(mesh.Faces.AddFace(i, j, c))
                    ngon = MeshNgon.Create(indices, facets)
                    mesh.Ngons.AddNgon(ngon)
    else:
        for x, y, z in vertices:
            mesh.Vertices.Add(x, y, z)
        for face in faces:
            f = len(face)
            if f < 3:
                continue
            if f == 3:
                mesh.Faces.AddFace(*face)
            elif f == 4:
                mesh.Faces.AddFace(*face)
            else:
                if MeshNgon:
                    centroid = centroid_polygon([vertices[index] for index in face])
                    c = mesh.Vertices.Add(* centroid)
                    facets = []
                    for i, j in pairwise(face + face[:1]):
                        facets.append(mesh.Faces.AddFace(i, j, c))
                    ngon = MeshNgon.Create(face, facets)
                    mesh.Ngons.AddNgon(ngon)

    mesh.Normals.ComputeNormals()
    mesh.Compact()

    guid = add_mesh(mesh)

    if guid != System.Guid.Empty:
        obj = find_object(guid)
        if obj:
            attr = obj.Attributes
            if color:
                attr.ObjectColor = FromArgb(*color)
                attr.ColorSource = ColorFromObject
            else:
                attr.ColorSource = ColorFromLayer
            if name:
                attr.Name = name
            obj.CommitChanges()
        return guid
Пример #9
0
import clr

clr.AddReference('RevitAPI')
clr.AddReference('RhinoCommon')
clr.AddReference('RhinoInside.Revit')

from Autodesk.Revit.DB import Transaction, ElementId, BuiltInCategory, DirectShape
from Rhino.Geometry import Point3d, Vector3d, Mesh, MeshingParameters, Sphere
from RhinoInside.Revit import Revit

import RhinoInside.Revit
clr.ImportExtensions(RhinoInside.Revit.Convert.Geometry)

doc = Revit.ActiveDBDocument

with Transaction(doc, "Sample7") as trans:
    trans.Start()

    sphere = Sphere(Point3d.Origin, 12 * Revit.ModelUnits)
    brep = sphere.ToBrep()
    meshes = Mesh.CreateFromBrep(brep, MeshingParameters.Default)

    category = ElementId(BuiltInCategory.OST_GenericModel)
    ds = DirectShape.CreateElement(doc, category)

    for mesh in meshes:
        ds.AppendShape(mesh.ToShape())

    trans.Commit()
Пример #10
0
def draw_mesh(vertices, faces, color=None, vertex_normals=None, texture_coordinates=None):
    """Draw mesh in Grasshopper.

    Parameters
    ----------
    vertices : list of point
        List of vertex locations.
    faces : list of list of int
        List of faces defined as lists of indices into the list of vertices.

    Other Parameters
    ----------------
    color : tuple, list or :class:`System.Drawing.Color`, optional
    vertex_normals : bool, optional
    texture_coordinates

    Returns
    -------
    list of :class:`Rhino.Geometry.Mesh`

    """
    mesh = Mesh()
    for a, b, c in vertices:
        mesh.Vertices.Add(a, b, c)
    for face in faces:
        f = len(face)
        if f < 3:
            continue
        if f == 3:
            mesh.Faces.AddFace(*face)
        elif f == 4:
            mesh.Faces.AddFace(*face)
        else:
            if MeshNgon:
                centroid = centroid_points([vertices[index] for index in face])
                c = mesh.Vertices.Add(*centroid)
                facets = []
                for i, j in pairwise(face + face[:1]):
                    facets.append(mesh.Faces.AddFace(i, j, c))
                ngon = MeshNgon.Create(face, facets)
                mesh.Ngons.AddNgon(ngon)

    if vertex_normals:
        count = len(vertex_normals)
        normals = CreateInstance(Vector3f, count)
        for i, normal in enumerate(vertex_normals):
            normals[i] = Vector3f(normal[0], normal[1], normal[2])
        mesh.Normals.SetNormals(normals)

    if texture_coordinates:
        count = len(texture_coordinates)
        tcs = CreateInstance(Point2f, count)
        for i, tc in enumerate(texture_coordinates):
            tcs[i] = Point2f(tc[0], tc[1])
        mesh.TextureCoordinates.SetTextureCoordinates(tcs)

    if color:
        count = len(mesh.Vertices)
        colors = CreateInstance(Color, count)
        for i in range(count):
            colors[i] = rs.coercecolor(color)
        mesh.VertexColors.SetColors(colors)

    return mesh