C2.1 Geometry Import

Import a surface geometry from rhino and convert to a compas mesh. (by Lotte)

Objectives

We will learn how to import a surface geometry from Rhino and convert it to a COMPAS mesh data structure. This also includes setting the file paths to serialise the data structure to a JSON file and visualising it.

Procedure

Rhino Surface

The surface we want to import from Rhino is in the Rhino file in the data folder in the github repository. It is created in between funicular boundary curves.

It is actually a polysurface that is already subdivided with appropriate spacings. The generation of such is excluded from the scope of this course. However, you can manually generate such a surface in Rhino by discretising the boundary curves into polylines with appropriate density and then using the RhinoCommand EdgeSrf to generate the polysurface.

Paths

First, we set the paths to the data folder that exists on the same level as the C. Form Finding and D. fabrication folder. This way, we can store and access the data there throughout the workshop.

# ==============================================================================
# Paths
# ==============================================================================

HERE = os.path.dirname(__file__)
DATA = os.path.abspath(os.path.join(HERE, '../..', 'data'))
FILE_O = os.path.join(DATA, 'cablenmesh_import.json')

Import from Rhino

Second, we can import the surface from Rhino by selecting the surface, wrapping it as a RhinoSurface, and converting the surface to a COMPAS mesh. This we will wrap inside a function that we then call.

# ==============================================================================
# Helpers
# ==============================================================================

def mesh_from_rhinosurface():
    """Make a mesh from a Rhino surface.
    """
    guid = compas_rhino.select_surface()
    surface = RhinoSurface.from_guid(guid)
    mesh = surface.to_compas(Mesh)
    return mesh


# ==============================================================================
# Import from Rhino
# ==============================================================================

mesh = mesh_from_rhinosurface()

Visualise in Rhino

Third, we can visualise the generated mesh in Rhino together with its vertex and face labels to better understand the generated data structure.

# ==============================================================================
#  Visualize
# ==============================================================================

artist = MeshArtist(mesh, layer="DF21_C2::01_Geometry Import::Mesh")
artist.clear_layer()
artist.draw_vertexlabels()
artist.draw_facelabels()
artist.draw()

We will place all the geometry in Rhino for this section C2. Applied Form Finding inside the parent layer DF21_C2 and all the subsequent steps in sublayers. With :: you can indicate the sublayer.

Export

Last, we can export the mesh data structure by serialising it to a JSON file.

# ==============================================================================
# Export
# ==============================================================================

mesh.to_json(FILE_O)

This will generate a file that you will see in the data folder, both in your File Explorer / Finder or in VS Code:

Last updated