[docs]classRhinoMesh(BaseRhinoGeometry):"""Wrapper for Rhino mesh objects. Attributes ---------- vertices (read-only) : list of point The coordinates of the vertices of the mesh. faces (read-only) : list of list of int Faces defined as lists of references into the list of vertices. vertex_color : list The colors of the vertices. Setting this to ``None`` unsets the vertex colors. border (read-only) : list The GUIDs of the border curves. """def__init__(self):super(RhinoMesh,self).__init__()@propertydefvertices(self):return[map(float,point)forpointincompas_rhino.rs.MeshVertices(self.geometry)]@propertydeffaces(self):returnmap(list,compas_rhino.rs.MeshFaceVertices(self.geometry))@propertydefvertex_colors(self):returnmap(list,compas_rhino.rs.MeshVertexColors(self.guid))@vertex_colors.setterdefvertex_colors(self,colors):compas_rhino.rs.MeshVertexColors(self.guid,colors)@propertydefborder(self):returncompas_rhino.rs.DuplicateMeshBorder(self.guid)
[docs]@classmethoddeffrom_selection(cls):"""Construct a mesh wrapper by selecting an existing Rhino mesh object. Parameters ---------- None Returns ------- :class:`compas_rhino.geometry.RhinoMesh` The wrapped line. """guid=compas_rhino.select_mesh()returncls.from_guid(guid)
[docs]@classmethoddeffrom_geometry(cls,geometry):"""Construct a mesh wrapper from an existing Rhino geometry object. Parameters ---------- geometry : :class:`Rhino.Geometry.Mesh` A Rhino mesh geometry. Returns ------- :class:`compas_rhino.geometry.RhinoMesh` The wrapped line. """mesh=cls()mesh.geometry=geometryreturnmesh
[docs]defto_compas(self,cls=None):"""Convert a Rhino mesh to a COMPAS mesh. Parameters ---------- cls : :class:`compas.datastructures.Mesh`, optional The mesh type. Returns ------- :class:`compas.datastructures.Mesh` The equivalent COMPAS mesh. """cls=clsorMeshfaces=[]forfaceinself.faces:ifface[0]==face[-1]:faces.append(face[:-1])elifface[-2]==face[-1]:faces.append(face[:-1])else:faces.append(face)mesh=cls.from_vertices_and_faces(self.vertices,faces)mesh.name=self.namereturnmesh
defclosest_point(self,point,maxdist=0.0):"""Compute the closest point on the mesh to a given point. Parameters ---------- point : point A point location. maxdist : float, optional The maximum distance between the closest point and the mesh. Default is ``0.0``. Returns ------- list The XYZ coordinates of the closest point. """face,point=self.geometry.ClosestPoint(Rhino.Geometry.Point3d(*point),maxdist)returnlist(point)defclosest_points(self,points,maxdist=None):"""Compute the closest points on the mesh to a list of input points. Parameters ---------- points : list of point The input points. maxdist : float, optional The maximum distance between the closest point and the mesh. Default is ``0.0``. Returns ------- list of point The XYZ coordinates of the closest points. """return[self.closest_point(point,maxdist)forpointinpoints]