How to explode a mesh in Grasshopper

Exploding a mesh is a key skill in handling meshes. Knowing the different ways is a good way of demonstrating you understand how to manipulate meshes. You might need to redefine some faces in your mesh, or you might want to colour a mesh face-by-face.

What does it mean to explode a mesh? It essentially means taking each face of the mesh, and making it a separate mesh in its own right. So a single mesh with 100 faces will become 100 meshes with one face.

There are broadly three ways of exploding a mesh, depending on what you want to do, your ability level, and the wider task you are trying to achieve. Let’s say we want to explode the mesh below.

Rhino mesh grid

Starting with the easiest…

Method 1: Use MeshEdit

Use the Explode component in the MeshEdit collection of components:

Grasshopper explode mesh with MeshEdit component

Notice how we feed a single mesh into the left, and a list comes out the other end.

This method is dependent upon MeshEdit being installed on the computer that the Grasshopper file is being used on. In cases where you can’t rely on this, for example in team working or when sharing files with clients, you might want to try…

Method 2: Use native Grasshopper components

Use this slightly clunkier method which grafts mesh data to create multiple meshes. The two components are ‘Construct Mesh’ and ‘Deconstruct Mesh’. Take care of the grafts and flattens. You could always turn these into a cluster for tidiness.

Explode Grasshopper mesh with native Grasshopper components

Method 3: Use C#

If you are writing C# and want to merge the mesh explode into a script for efficiency, or you just want to show off your Grasshopper Geek credentials, you can use the following method:

  List<Mesh> Explode(Mesh m)
  {
    var rtnlist = new List<Mesh>();

    for (int f = 0; f < m.Faces.Count; f++)
    {
      var newmesh = new Mesh();
      newmesh.Vertices.Add(m.Vertices[m.Faces[f].A]);
      newmesh.Vertices.Add(m.Vertices[m.Faces[f].B]);
      newmesh.Vertices.Add(m.Vertices[m.Faces[f].C]);
      if(m.Faces[f].IsQuad) newmesh.Vertices.Add(m.Vertices[m.Faces[f].D]);

      if(m.Faces[f].IsTriangle) newmesh.Faces.AddFace(0, 1, 2);
      if(m.Faces[f].IsQuad) newmesh.Faces.AddFace(0, 1, 2, 3);

      rtnlist.Add(newmesh);
    }

    return rtnlist;
  }

 

…which you can easily call with:

    M = Explode(m);

 

This gives a nice, tidy component:

Explode mesh in Grasshopper C# component

Learning to manipulate meshes in C# is a great skill to have, and I recommend you get into it. Recently, I have used C# to turn curves into data-light meshes, and to turn curves into roads suitable for mapping.

Whichever method you’ve chosen, if you bake the result, you should end up with something like this:

Exploded Rhino grid mesh