# Oops...

This website is made for modern browsers. You are seeing this, because your browser is missing a feature or two. Please install the latest update or switch to a modern browser. See you soon.

# Trim meshes and cap holes

In general, it’s advised to generate meshes as late as possible in the algorithm because when we convert surfaces to meshes we lose topographic information

. If possible, trim the surface
first and then convert the remaining surface into a mesh. Yet, this is not always possible, so this how-to guide illustrates different possibilities to trim a mesh depending on the trimming object and how to cap holes that were creating thereby.

### Trim a mesh with another one

For this method, we look at random meshes and then trim one with the other. In the following, we have a sphere that is interpenetrated with a cylinder and the part of the sphere that is inside the cylinder will be cropped. Then, the created cutout is closed with a planar cap.

The component Mesh Sphere

Mesh Sphere (MSphere)
Mesh  >  Primitive  >  Mesh Sphere
Create a mesh sphere.
Inputs
Base (B)Base plane
U Count (U)Number of faces around sphere
V Count (V)Number of faces from pole to pole
Outputs
Mesh (M)Mesh sphere
directly generates the said sphere. For the cylinder, we use Cylinder
Cylinder (Cyl)
Surface  >  Primitive  >  Cylinder
Create a cylindrical surface.
Inputs
Base (B)Base plane
Length (L)Cylinder height
Outputs
Cylinder (C)Resulting cylinder
to create the surface and set matching parameters. Next we use Mesh Brep
Mesh Brep (Mesh)
Mesh  >  Util  >  Mesh Brep
Create a mesh that approximates Brep geometry
Inputs
Brep (B)Brep geometry
Settings (S)Settings to be used by meshing algorithm
Outputs
Mesh (M)Mesh approximation
to convert the cylinder into a mesh.

The component Mesh Split

Mesh Split (MSplit)
Intersect  >  Shape  >  Mesh Split
Mesh Mesh split
Inputs
Mesh (M)Mesh to split
Splitters (S)Meshes to split with
Outputs
Result (R)Result of mesh split
will split the sphere along the intersection curve with the cylinder. After the split, we get the remaining surface via List Item
List Item (Item)
Sets  >  List  >  List Item
Retrieve a specific item from a list.
Inputs
List (L)Base list
Index (i)Item index
Wrap (W)Wrap index to list bounds
Outputs
Item (i)Item at {i'}
. In this case the preset value 0 of the index i is what we are looking for. Otherwise, we have to change the index or set up some components to calculate the index of the desired surface (it’s often the one with the largest area). We have now performed the trimming operation.

To close the remaining openings with another mesh, we first have to get the edges of the holes with Mesh Edges

Mesh Edges (MEdges)
Mesh  >  Analysis  >  Mesh Edges
Get all the edges of a mesh
Inputs
Mesh (M)Mesh for edge extraction
Outputs
Naked Edges (E1)Edges with valence 1 (a single adjacent face)
Interior Edges (E2)Edges with valence 2 (two adjacent faces)
Non-Manifold Edges (E3)Edges with valence 3 or higher
and then we find them at output grip E1. Join Curves
Join Curves (Join)
Curve  >  Util  >  Join Curves
Join as many curves as possible
Inputs
Curves (C)Curves to join
Preserve (P)Preserve direction of input curves
Outputs
Curves (C)Joined curves and individual curves that could not be joined.
will merge these edges to a polyline on each opening (this curves equal the intersection curves). Next, Discontinuity
Discontinuity (Disc)
Curve  >  Analysis  >  Discontinuity
Find all discontinuities along a curve.
Inputs
Curve (C)Curve to analyze
Level (L)Level of discontinuity to test for (1=C1, 2=C2, 3=Cinfinite)
Outputs
Points (P)Points at discontinuities
Parameters (t)Curve parameters at discontinuities
will generate points at the vertices of the polylines and we use Planar
Planar (Planar)
Curve  >  Analysis  >  Planar
Test a curve for planarity.
Inputs
Curve (C)Curve to evaluate
Outputs
Planar (p)Planarity of curve
Plane (P)Curve plane
Deviation (D)Deviation from curve plane
to get the plane at each opening. Both are then combined to generate a Delaunay Mesh
Delaunay Mesh (Del)
Mesh  >  Triangulation  >  Delaunay Mesh
Delaunay triangulation
Inputs
Points (P)Points for triangulate
Plane (Pl)Optional base plane. If no plane is provided, then the best-fit plane will be used.
Outputs
Mesh (M)Mesh
that caps the holes
Using the Delaunay algorithm on the edge vertices will create a mesh in which some triangular faces span across the entire length of the opening. This generation is not adequate for FEM calculations. See the end of this page for an alternative solution.
Using the Delaunay algorithm on the edge vertices will create a mesh in which some triangular faces span across the entire length of the opening. This generation is not adequate for FEM calculations. See the end of this page for an alternative solution.. In this example we have to graft the planes to match the data structure of the points.

As an alternative, we can also use the component Mesh | Mesh

Mesh | Mesh (MMX)
Intersect  >  Physical  >  Mesh | Mesh
Mesh Mesh intersection
Inputs
Mesh A (A)First mesh
Mesh B (B)Second mesh
Outputs
Intersections (X)Intersection polylines
to generate the intersection curves. This results in fewer components on the canvas but is slightly slower in computation, because the intense solving of intersections is done twice.

### Trim a mesh with a plane

Another possibility to split a mesh is with a plane. Let’s assume is any mesh with an assigned thickness. This can be quickly done with the Grasshopper plugins Weaverbird or Element* and is a common scenario for 3D printing.

Now, we use Mesh Split Plane

Mesh Split Plane (MSplit)
Mesh  >  Util  >  Mesh Split Plane
Split a mesh with an infinite plane.
Inputs
Mesh (M)Mesh to split
Plane (P)Splitting plane
Outputs
Above (A)Pieces above the plane.
Below (B)Pieces below the plane.
to split the mesh. We find the desired half of the mesh in one of the outputs. Just like above, we use Mesh Edges
Mesh Edges (MEdges)
Mesh  >  Analysis  >  Mesh Edges
Get all the edges of a mesh
Inputs
Mesh (M)Mesh for edge extraction
Outputs
Naked Edges (E1)Edges with valence 1 (a single adjacent face)
Interior Edges (E2)Edges with valence 2 (two adjacent faces)
Non-Manifold Edges (E3)Edges with valence 3 or higher
and Join Curves
Join Curves (Join)
Curve  >  Util  >  Join Curves
Join as many curves as possible
Inputs
Curves (C)Curves to join
Preserve (P)Preserve direction of input curves
Outputs
Curves (C)Joined curves and individual curves that could not be joined.
to obtain the intersection curves. And again, there is a computationally more expensive shortcut given by the component Mesh | Plane
Mesh | Plane (Sec)
Intersect  >  Mathematical  >  Mesh | Plane
Solve intersection events for a Mesh and a Plane (otherwise known as section).
Inputs
Mesh (M)Base Mesh
Plane (P)Section plane
Outputs
Curves (C)Section polylines
.

Unlike before, the intersection curve in this example has inflection points and the opening is concave. Thus, the Delaunay algorithm will not generate the desired mesh. We have to take a little detour by generating a Boundary Surfaces

Boundary Surfaces (Boundary)
Surface  >  Freeform  >  Boundary Surfaces
Create planar surfaces from a collection of boundary edge curves.
Inputs
Edges (E)Boundary curves
Outputs
Surfaces (S)Resulting boundary surfaces
within each intersection curve and then convert them to a mesh with Mesh Brep
Mesh Brep (Mesh)
Mesh  >  Util  >  Mesh Brep
Create a mesh that approximates Brep geometry
Inputs
Brep (B)Brep geometry
Settings (S)Settings to be used by meshing algorithm
Outputs
Mesh (M)Mesh approximation
.

### Particularities of non-planar openings

In the examples above, the intersection curves were planar, which is not always true. For example, if two cylinders intersect, we get a twisted intersection curve. In case of meshed cylinders, this intersection curve is a polyline and there is no distinct method to cap the opening. We then have to think of an appropriate way that suits our design. In Grasshopper, Fragment Patch

Fragment Patch (FPatch)
Surface  >  Freeform  >  Fragment Patch
Create a fragmented patch from a polyline boundary
Inputs
Boundary (B)Fragment polyline boundary
Outputs
Patch (P)Fragmented patch
can be used to create a Brep that technically covers a non-planar polyline, but the result might not be aesthetically pleasing.

For these twisted intersection curves, it’s easier to keep the solids as surfaces and solve there intersection. We can then use Patch

Patch (Patch)
Surface  >  Freeform  >  Patch
Create a patch surface
Inputs
Curves (C)Curves to patch
Points (P)Points to patch
Spans (S)Number of spans
Flexibility (F)Patch flexibility (low number; less flexibility)
Trim (T)Attempt to trim the result
Outputs
Patch (P)Patch result
to cover the twisted intersection curve in a more aesthetically pleasing way and this surface can be converted into a mesh.

To check, whether the generated caps close the openings and everything forms is a tight union, we can combine the individual meshes with Mesh Join

Mesh Join (MJoin)
Mesh  >  Util  >  Mesh Join
Join a set of meshes into a single mesh
Inputs
Meshes (M)Meshes to join
Outputs
Mesh (M)Mesh join result
(don’t forget to flatten). We can then use Disjoint Mesh
Disjoint Mesh (Disjoint)
Mesh  >  Util  >  Disjoint Mesh
Split a mesh into disjoint pieces.
Inputs
Mesh (M)Mesh to split
Outputs
Meshes (M)Disjoint pieces
and if the meshes shared a common typography, there still should be only one mesh. If there are more meshes as output than as input, the mesh edges of neighboring meshes were not aligned or the vertices were not lying on top of each other.

### Particularities of other regular openings

The methods described above will not always be satisfying in some corner cases. For example if we need a mesh suitable for FEM calculations or have an intersection polyline that doesn’t deflect at every vertex. To solve these issues, we have to make sure that every vertex is part of the mesh or that additional faces are creating within the region of the opening.

To solve the above, we can use Mesh Edges

Mesh Edges (MEdges)
Mesh  >  Analysis  >  Mesh Edges
Get all the edges of a mesh
Inputs
Mesh (M)Mesh for edge extraction
Outputs
Naked Edges (E1)Edges with valence 1 (a single adjacent face)
Interior Edges (E2)Edges with valence 2 (two adjacent faces)
Non-Manifold Edges (E3)Edges with valence 3 or higher
and Join Curves
Join Curves (Join)
Curve  >  Util  >  Join Curves
Join as many curves as possible
Inputs
Curves (C)Curves to join
Preserve (P)Preserve direction of input curves
Outputs
Curves (C)Joined curves and individual curves that could not be joined.
to generate the boundary curve, just like before. Besides creating Boundary Surfaces
Boundary Surfaces (Boundary)
Surface  >  Freeform  >  Boundary Surfaces
Create planar surfaces from a collection of boundary edge curves.
Inputs
Edges (E)Boundary curves
Outputs
Surfaces (S)Resulting boundary surfaces
, we also use Explode
Explode (Explode)
Curve  >  Util  >  Explode
Explode a curve into smaller segments.
Inputs
Curve (C)Curve to explode
Recursive (R)Recursive decomposition until all segments are atomic
Outputs
Segments (S)Exploded segments that make up the base curve
Vertices (V)Vertices of the exploded segments
to deconstruct the intersection curve(s). This way, we get vertices separated for each curve. Karamba3D offers a special component Mesh Breps (Karamba3D)
Mesh Breps (Karamba3D) (Mesh Breps)
Karamba3D  >  8.Utilities  >  Mesh Breps (Karamba3D)
Meshes multiple Breps. Allows to include manifold edges and points.
Inputs
Brep (Brep)Breps or surfaces to mesh
Inclusion Points (IPts)Points to include into the mesh
Mesh Resolution (MRes)Target mesh size [m]
Edge Refinement Factor (ERef)Resolution refinement at Brep edges.
Point Reduction (PRed)Optional reduction of points at narrowing UV-spaces. Disabling point reduction results in a much faster output but mesh vertices may have a greater difference of density
Smoothing Step Size (SStep)Smoothing step size for each iteration ('0' means no smoothing)
Note that mesh smoothing can result self-overlapping meshes at inclusion points!
Smoothing Iterations (SIter)Smoothing iterations ('0' means no smoothing)
Note that mesh smoothing can result self-overlapping meshes at inclusion points!
Outputs
Mesh (Mesh)Output Mesh
Info (Info)Output stats
that generates meshes which include the provided points as mesh vertices.

This page is open source. Edit it on GitHub or see how you can contribute.