Tuesday, March 15, 2016

Working with Meshes in Rhino and Grasshopper

This posts discusses creating, modifying, smoothing and troubleshooting meshes in Rhino and Grasshopper. It also presents a number of plug-ins very useful in dealing with meshes. These are Weaverbird and Lunchbox

Mesh Overview

A mesh is a collection of vertices and polygons that define the shape of an object. Meshes in Rhino consist of triangles and quadrilaterals.

Rhino creates triangles and quadrilaterals meshes for export into various file formats. If a mesh is generated from a solid, the mesh will be seamless/watertight.

You can convert between NURBS objects and Meshes using the Mesh command:
Mesh (from the pull-down menus: Mesh > From NURBS Object). You have control over the detail, and thus smoothness, of the mesh. 

In the example below a NURBS object is shown at the left. To the right are three mesh representations of the same object. Each has a different resolution or face count. The first mesh to the left is low resolution and will have a faceted silhouette. The mesh to its right is quite high resolution and is smooth, but not as smooth as the NURBS surface. The example on the far right was created from the mesh to its left by running a face reduction algorithm.

You can reduce the complexity of a mesh object by using the ReduceMesh command:
ReduceMesh (Mesh > Mesh Edit Tools > Reduce Mesh)

Finding Mesh Problems

A common use for meshes is 3D printing. The printers require a mesh rather than a NURBS surface or polysurface. 3D printers can be quite fussy about the meshes they need. Essentially they need to be closed – no holes, with no extra faces present. Rhino provides tools to analyze NURBS objects and Meshes to find problems.

ShowEdges (Analyze > Edge Tools > Show Edges)
This command is particularly valuable as it shows what are know as “non-manifold edges” and “naked edges”. To 3D print you can’t have either of these issues.

Naked Edges: A naked edge is a surface, polysurface or mesh edge that is not connected to another edge. Solid objects have no naked edges.

In the example below two faces are missing. The edges of the holes are not connected to another edge and are thus naked.

To fix this problem you could use the FillMeshHoles command (Mesh > Mesh Repair Tools > Fill All Holes).

Non-Manifold Edges: Edges of polysurfaces or meshes that have more than two faces joined to a single edge are non-manifold.

In the example below a mesh object has an internal face spanning the center.

The edge in the middle of the yellow faces below is shared by three faces and is thus non-manifold.

The same is true for every side of the box because the internal face touches every side.

The internal face can be deleted to fix the problem. To do so use the DeleteMeshFaces command (Mesh > Mesh Edit Tools > Delete Mesh Faces). 

Rhino also has a Mesh Repair command. This functions like a wizard to guide you through the process of finding and fixing mesh problems. With imported data this command can be quite useful to take a sloppy mesh and make it usable. 

Building Meshes in Grasshopper

This example shows the Grasshopper components which generate triangle or quad meshes. These simple examples constructs one or two faces as shown below.

This example uses the Triangle component and specifies three indices to the corners of the triangle. These are numbers which indicate which position in the vertex list is used by each corner. One triangle is built using indices 0, 1 and 2. The other is built using 2, 1 and 3. The order is important. They should be ordered so that when viewed from the top the go in a counterclockwise direction. This will result in the surface normal of the face pointing upward.

A quadrilateral face is built using the Mesh Quad (Quad) component. In this case it takes a vertex list of four 3D points and four indices into that vertex list.

The vertices are specified using a Panel component which is set to Multiline Data (available from the right-click menu on the Panel). Unless you use Multiline Data you'll get an error. Each vertex is the 3D coordinate in world space and appears on its own line:

It's also possible to generate meshes from a set of points. Here's a simple definition which does so using Delaunay Triangulation.

Below the Populate 2D (Pop2D) component is used to generate random points inside a rectangle. The the Delaunay (Del) component is used to generate a mesh using them as the corner vertices. This method of triangulation is designed to minimize the number of "sliver" triangles (long skinny triangles). Sometimes these are unavoidable, for example along the edges. These skinny triangles are not ideal for analysis software (for example when evaluating structural performance of a design). 

In the example below a Voronoi component is wired in to create the Voronoi pattern.

Here's the Voronoi tessellation shown in green:

A Voronoi pattern is the dual of the Delaunay triangulation. The dual of a triangle is constructed by taking its center point (shown in green below) and running a line through the midpoint of each edge (shown in gray). Connect the ends of these lines with the corners of the triangle. This results in a hexagon (shown in blue). This hexagon is the dual of the triangle. A Voronoi pattern does not necissarily have to be a six-sided cell (it is dependent on the triangles, their shape, and their position in the overall mesh).

Subdivision Surfaces

Subdivision surfaces allow us to get smooth meshes from any given input mesh. An excellent Grasshopper plug-in for this purpose is Weaverbird.

Subdividing Triangle Meshes

A good method of subdividing triangle meshes is the Loop algorithm developed by Charles Loop. The algorithm is simple: Each edge of each triangle of the source mesh gets a new midpoint added. A new triangle is built by connecting these midpoints to create 4 sub-triangles.

Each iteration of the algorithm approaches what's known as the limit surface (the surface that would result if the algorithm were run infinite times).

In this example we start with an Icosahedron on the left. Loop subdivision is done 1, 2, and 3 iterations moving left to right. The mesh gets smoother and approaches the limit surface.

Subdividing Quadrangular Meshes

The Catmull-Clark subdivision method is a good choice for subdividing quad meshes (it also works well on triangle meshes). This method adds new vertices for each face in an iterative manner resulting in a smoother surface.

In the example below the mesh on the left is subdivided. From left to right L=1, 2 and 3 were used. The Fixed Naked Edges method (S=0) was used on each which is why the edges are all straight.

In the example below S=1 was used to smooth the edges (allow them to move like a spline rather than being locked as straight lines). Again, L values of 1,2 and 3 were used.

A closer look at L=2 and 3 with Smooth (S=1) versus Fixed Naked Edges (S=0).

Picture Frames and Thickening

Weaverbird has some interesting tools to make "picture frames" from each face of a mesh. A hole is placed in the center of each face with a solid edge around it. When combined with a Mesh Thicken component some interesting frame structures can be generated.

This produces clean meshes with no naked edges or self-intersections.

This has obvious advantages over using the Pipe component and winding up with unresolved intersections.

There's another way of doing this - see 3D Printed Cytoskeleton Figure Sculpt. That example is a figure sculpture but the method applies to any mesh.

Converting Rhino Surfaces and Solids to Meshes in Grasshopper

There are two key components used to convert surfaces and solids (BReps in Grasshopper terminology) into meshes in Grasshopper. These are: Mesh Brep and Settings (Custom):

The BRep is the source geometry to convert. The Settings provide control over the details of tesselation. Sockets Max Edge, Max Angle and Planes are key parameters:
  • Max Edge: Maximum allowed edge length. 
  • Max Angle: Maximum allowed angle (in degrees) between the normals of two adjacent quads. 
  • Planes: Planar faces are meshed with a minimum amount of triangles. 
Some forms, for example a sphere mesh quite cleanly and in an organized way. Other forms are triangulated in far less obviously rational ways:


Triangle meshes are always planar - each face is perfectly flat. This is not necessarily so with quad meshes.

You can use a simple definition like this to show which faces are planar.

The example mesh below had some of the vertices pushed inward resulting is several warped faces.

The Face Boundaries (FaceB) and the Planar components are used. FaceB creates polyline curves for each face. Planar returns a list of True or False values for each face indicating if that curve is planar or not. The Cull Pattern component is used to remove those faces which are not planar. Then the Construct Mesh command is used to create a new mesh using only the planar faces. The results are shown below. As you can see, the newly constructed mesh is missing the non-planar faces.

Lunchbox Paneling

The Lunchbox Plug-In contains a series of components for paneling using triangles, quads, and hexagons.

Generating Frames from Triangle Panel Surfaces

The following definition can be used a take a polysurface composed of triangular surfaces and generate a frame:

This example was paneled with Lunchbox Triangle Panel C (TriC) then run through the above definition. The result is a water-tight mesh.

Here's a definition which tessellates any polysurface by adding a new vertex in the center of each surface then building triangles out to the edges. These triangles are combined and unified into a new mesh. That mesh is then run through Loop subdivision, converted to thickened frames. Try it on Polyhedra from the Rhino Polyhedra plug-in :)

Export of Meshes for Import into Other Programs or 3D Printing

After generating meshes it's common to want to export them out of Rhino. There are a few file formats which work well. The STL format is one. This is a very common format for use with 3D printers.

Another useful mesh format is OBJ. OBJ typically is defined with Y up instead of Z. To export you can simply use the SaveAs... command then use the Save as type drop-down to select a format.

There is a checkbox for Rhino export to swap these so the files go out (or come in during OBJ import) in the correct orientation.

Meshes and Kangaroo Physics

Meshes are important when it comes to physics simulation. See this post - Kangaroo Physics Simulation for Grasshopper - for details on using Meshes with Kangaroo.

No comments:

Post a Comment