Exemplo n.º 1
0
def mesh_from_surface_heightfield(cls, guid, density=(10, 10)):
    """Create a mesh data structure from a point grid aligned with the uv space of a Rhino NURBS surface.

    Parameters
    ----------
    cls : Mesh
        The mesh type.
    guid : str
        The GUID of the surface.
    density : tuple
        The density of the point grid in the u and v directions.

    Returns
    -------
    Mesh
        A mesh object.

    See Also
    --------
    * :class:`compas_rhino.geometry.RhinoSurface`

    Examples
    --------
    >>>

    """
    try:
        u, v = density
    except Exception:
        u, v = density, density

    surface = RhinoSurface(guid)

    mesh = cls()

    vertices = surface.heightfield(density=(u, v), over_space=True)

    for x, y, z in vertices:
        mesh.add_vertex(x=x, y=y, z=z)

    for i in range(u - 1):
        for j in range(v - 1):
            face = ((i + 0) * v + j,
                    (i + 0) * v + j + 1,
                    (i + 1) * v + j + 1,
                    (i + 1) * v + j)
            mesh.add_face(face)

    return mesh
Exemplo n.º 2
0
    def from_guid(guid):
        """Create a ``RhinoGeometry`` instance of the correct type based on a given guid.

        Parameters
        ----------
        guid : str or System.Guid
            The *guid* of the Rhino object.

        Returns
        -------
        RhinoPoint
            If the type of the Rhino object is ``rs.filter.point``.
        RhinoCurve
            If the type of the Rhino object is ``rs.filter.curve``.
        RhinoMesh
            If the type of the Rhino object is ``rs.filter.mesh``.
        RhinoSurface
            If the type of the Rhino object is ``rs.filter.surface``.

        Examples
        --------
        >>>

        """
        from compas_rhino.geometry import RhinoPoint
        from compas_rhino.geometry import RhinoCurve
        from compas_rhino.geometry import RhinoMesh
        from compas_rhino.geometry import RhinoSurface

        otype = rs.ObjectType(guid)

        if otype == rs.filter.point:
            return RhinoPoint(guid)

        if otype == rs.filter.curve:
            return RhinoCurve(guid)

        if otype == rs.filter.mesh:
            return RhinoMesh(guid)

        if otype == rs.filter.surface:
            return RhinoSurface(guid)
import compas_rhino

from compas_rhino.helpers import mesh_from_guid

from compas_rhino.conduits import LinesConduit
from compas_rhino.geometry import RhinoSurface
from compas_rhino.artists import MeshArtist

# make a mesh datastructure from a Rhino mesh object
# and select a target surface

guid = compas_rhino.select_mesh()
mesh = mesh_from_guid(Mesh, guid)

guid = compas_rhino.select_surface()
surf = RhinoSurface(guid)

# extract the input for the smoothing algorithm from the mesh
# and identify the boundary as fixed

vertices = mesh.get_vertices_attributes('xyz')
faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
adjacency = [mesh.vertex_faces(key, ordered=True) for key in mesh.vertices()]
fixed = set(mesh.vertices_on_boundary())

# make a conduit for visualization
# and a callback for updating the conduit
# and for pulling the free vertices back to the surface
# at every iteration

edges = list(mesh.edges())