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
def from_guid(cls, guid): rhinosurface = RhinoSurface.from_guid(guid) mesh = rhinosurface.to_compas(cleanup=False) subdobject = cls(mesh) subdobject.coarse = mesh return subdobject
def from_rhinosurface(cls, guid, **kwargs): """Construct a FormDiagram from a Rhino surface represented by its GUID. Parameters ---------- guid : str A globally unique identifier. Returns ------- FormDiagram A FormDiagram object. Examples -------- .. code-block:: python import compas_rhino from compas_tna.diagrams import FormDiagram guid = compas_rhino.select_surface() form = FormDiagram.from_rhinosurface(guid) """ from compas_rhino.geometry import RhinoSurface mesh = RhinoSurface.from_guid(guid).uv_to_compas(cls, **kwargs) if 'name' in kwargs: mesh.name = kwargs['name'] return mesh
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)
def from_polysurface(cls, guid, frame): """Class method for constructing a block from a Rhino poly-surface. Parameters ---------- guid : str The GUID of the poly-surface. frame : :class:`Frame` Origin frame of the element. Notes ----- In Rhino, poly-surfaces are organised such that the cycle directions of the individual sub-surfaces produce normal vectors that point out of the enclosed volume. The normal vectors of the faces of the mesh, therefore also point "out" of the enclosed volume. """ from compas_rhino.geometry import RhinoSurface element = cls(frame) element._source = RhinoSurface.from_guid(guid) element._mesh = element._source.brep_to_compas() return element
def RunCommand(is_interactive): scene = get_scene() if not scene: return guid = compas_rhino.select_surface() if not guid: return u = PatternObject.SETTINGS['from_surface.density.U'] v = PatternObject.SETTINGS['from_surface.density.V'] options = ['U', 'V'] while True: option = compas_rhino.rs.GetString("Enter values for U and V:", strings=options) if not option: break if option == 'U': u = compas_rhino.rs.GetInteger("Density U", u, 2, 100) continue if option == 'V': v = compas_rhino.rs.GetInteger("Density V", v, 2, 100) continue density = u + 1, v + 1 pattern = RhinoSurface.from_guid(guid).uv_to_compas(cls=Pattern, density=density) compas_rhino.rs.HideObject(guid) scene.clear() scene.add(pattern, name='pattern') scene.update() print( "Pattern object successfully created. Input surface has been hidden.")
def from_rhinosurface(cls, guid, u=20, v=10): """Make a cable net from a Rhino surface. Parameters ---------- guid : str The GUID of the Rhino surface. u : int (10) The number of isolines in the "u" direction. Default is `10`. v : int (10) The number of isolines in the "v" direction. Default is `10`. Returns ------- :class:`Cablenet` An instance of a cable net. """ from compas_rhino.geometry import RhinoSurface return RhinoSurface.from_guid(guid).uv_to_compas(cls=cls, density=(u, v))
def from_polysurface(cls, guid): """Class method for constructing a block from a Rhino poly-surface. Parameters ---------- guid : str The GUID of the poly-surface. Returns ------- Block The block corresponding to the poly-surface. Notes ----- In Rhino, poly-surfaces are organised such that the cycle directions of the individual sub-surfaces produce normal vectors that point out of the enclosed volume. The normal vectors of the faces of the mesh, therefore also point "out" of the enclosed volume. """ from compas_rhino.geometry import RhinoSurface surface = RhinoSurface.from_guid(guid) return surface.to_compas(cls)
HERE = os.path.dirname(__file__) FILE = os.path.join(HERE, 'data', 'blocks.json') # ============================================================================== # Blocks and Blanks # ============================================================================== guids = compas_rhino.select_surfaces() blocks = [] world = Frame.worldXY() for guid in guids: surface = RhinoSurface.from_guid(guid) block = surface.to_compas() block.name = str(guid) bottom = sorted( block.faces(), key=lambda face: dot_vectors(block.face_normal(face), [0, 0, -1]))[-1] plane = block.face_centroid(bottom), block.face_normal(bottom) frame = Frame.from_plane(plane) T = Transformation.from_frame_to_frame(frame, world) block.transform(T) blank = Box.from_bounding_box(block.bounding_box())
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())
from compas_3gs.rhino import draw_network_external_forces from compas_3gs.rhino import draw_network_internal_forces from compas_3gs.rhino import Mesh3gsArtist, VolMesh3gsArtist from compas_3gs.rhino import Network3gsArtist try: import rhinoscriptsyntax as rs except ImportError: compas.raise_if_ironpython() # select the polysurface which you create in Rhino guid = rs.GetObject("select a closed polysurface", filter=rs.filter.polysurface) # turn Rhino polysurface to a COMPAS single polyhedral cell cell = RhinoSurface.from_guid(guid).brep_to_compas(cls=Cell()) rs.HideObjects(guid) # draw the polyhedral cell layer = 'cell' cellartist = Mesh3gsArtist(cell, layer=layer) cellartist.draw() cellartist.redraw() from compas_3gs.operations import check_cell_convexity print(check_cell_convexity(cell)) print(cell) #================== cell_cut_face_subdiv ==================