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
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
def _create_rhino_mesh(vertices, faces): vertices = [vertices[i:i + 3] for i in range(0, len(vertices), 3)] faces = [faces[i:i + 3] for i in range(0, len(faces), 3)] mesh = RhinoMesh() for a, b, c in vertices: mesh.Vertices.Add(a, b, c) for face in faces: mesh.Faces.AddFace(face[0], face[1], face[2]) return mesh
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
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