Video thumbnail
Collecting Transformations
In this video, we begin by creating the 14 base meshes that we’ll need for the Marching Cubes algorithm. Then, we rotate and mirror these meshes in different ways, collecting each sequence as a separate transformation to apply to our cube corners and the Boolean patterns associated with each base-case mesh.

Back to Marching Cubes
Code
The code below creates the 14 base meshes for our lookup table. The code includes an input of ‘vertices’ as an IList and two outputs, ‘mesh_tree’ and ‘bool_patterns’, for the Rhino scripting component. Make sure these inputs and outputs match the inputs and outputs for the scripting component this code occupies.
    
// Grasshopper Script Instance
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{
  
  private void RunScript(
	IList<Point3d> vertices,
	ref object mesh_tree,
	ref object bool_patterns)
  {
    DataTree<Mesh> m_tree = new DataTree<Mesh>();
    DataTree<int> i_tree = new DataTree<int>();

    //

    Mesh m0 = new Mesh();
    GH_Path pth_0 = new GH_Path(0);

    foreach (Point3d vertex in vertices)
    {
      m0.Vertices.Add(vertex);
    }
    m0.Faces.AddFace(0, 8, 3);
    m_tree.Add(m0, pth_0);

    i_tree.Add(0, pth_0);
    i_tree.Add(1, pth_0);
    i_tree.Add(1, pth_0);
    i_tree.Add(1, pth_0);

    i_tree.Add(1, pth_0);
    i_tree.Add(1, pth_0);
    i_tree.Add(1, pth_0);
    i_tree.Add(1, pth_0);

    //

    Mesh m1 = new Mesh();
    GH_Path pth_1 = new GH_Path(1);

    foreach (Point3d vertex in vertices)
    {
      m1.Vertices.Add(vertex);
    }
    m1.Faces.AddFace(1, 8, 3);
    m1.Faces.AddFace(1, 9, 8);
    m_tree.Add(m1, pth_1);

    i_tree.Add(0, pth_1);
    i_tree.Add(0, pth_1);
    i_tree.Add(1, pth_1);
    i_tree.Add(1, pth_1);

    i_tree.Add(1, pth_1);
    i_tree.Add(1, pth_1);
    i_tree.Add(1, pth_1);
    i_tree.Add(1, pth_1);

    //

    Mesh m2 = new Mesh();
    GH_Path pth_2 = new GH_Path(2);

    foreach (Point3d vertex in vertices)
    {
      m2.Vertices.Add(vertex);
    }
    m2.Faces.AddFace(0, 8, 3);
    m2.Faces.AddFace(9, 5, 4);
    m_tree.Add(m2, pth_2);

    i_tree.Add(0, pth_2);
    i_tree.Add(1, pth_2);
    i_tree.Add(1, pth_2);
    i_tree.Add(1, pth_2);

    i_tree.Add(1, pth_2);
    i_tree.Add(0, pth_2);
    i_tree.Add(1, pth_2);
    i_tree.Add(1, pth_2);

    //

    Mesh m3 = new Mesh();
    GH_Path pth_3 = new GH_Path(3);

    foreach (Point3d vertex in vertices)
    {
      m3.Vertices.Add(vertex);
    }
    m3.Faces.AddFace(0, 8, 3);
    m3.Faces.AddFace(6, 5, 10);
    m_tree.Add(m3, pth_3);

    i_tree.Add(0, pth_3);
    i_tree.Add(1, pth_3);
    i_tree.Add(1, pth_3);
    i_tree.Add(1, pth_3);

    i_tree.Add(1, pth_3);
    i_tree.Add(1, pth_3);
    i_tree.Add(0, pth_3);
    i_tree.Add(1, pth_3);

    //

    Mesh m4 = new Mesh();
    GH_Path pth_4 = new GH_Path(4);

    foreach (Point3d vertex in vertices)
    {
      m4.Vertices.Add(vertex);
    }
    m4.Faces.AddFace(0, 9, 3);
    m4.Faces.AddFace(3, 9, 11);
    m4.Faces.AddFace(11, 9, 10);
    m_tree.Add(m4, pth_4);

    i_tree.Add(0, pth_4);
    i_tree.Add(1, pth_4);
    i_tree.Add(1, pth_4);
    i_tree.Add(1, pth_4);

    i_tree.Add(0, pth_4);
    i_tree.Add(0, pth_4);
    i_tree.Add(0, pth_4);
    i_tree.Add(0, pth_4);

    //

    Mesh m5 = new Mesh();
    GH_Path pth_5 = new GH_Path(5);

    foreach (Point3d vertex in vertices)
    {
      m5.Vertices.Add(vertex);
    }
    m5.Faces.AddFace(3, 1, 8);
    m5.Faces.AddFace(1, 9, 8);
    m5.Faces.AddFace(7, 6, 11);
    m_tree.Add(m5, pth_5);

    i_tree.Add(0, pth_5);
    i_tree.Add(0, pth_5);
    i_tree.Add(1, pth_5);
    i_tree.Add(1, pth_5);

    i_tree.Add(1, pth_5);
    i_tree.Add(1, pth_5);
    i_tree.Add(1, pth_5);
    i_tree.Add(0, pth_5);

    //

    Mesh m6 = new Mesh();
    GH_Path pth_6 = new GH_Path(6);

    foreach (Point3d vertex in vertices)
    {
      m6.Vertices.Add(vertex);
    }
    m6.Faces.AddFace(1, 9, 0);
    m6.Faces.AddFace(6, 5, 10);
    m6.Faces.AddFace(2, 3, 11);
    m_tree.Add(m6, pth_6);

    i_tree.Add(1, pth_6);
    i_tree.Add(0, pth_6);
    i_tree.Add(1, pth_6);
    i_tree.Add(0, pth_6);

    i_tree.Add(1, pth_6);
    i_tree.Add(1, pth_6);
    i_tree.Add(0, pth_6);
    i_tree.Add(1, pth_6);

    //

    Mesh m7 = new Mesh();
    GH_Path pth_7 = new GH_Path(7);

    foreach (Point3d vertex in vertices)
    {
      m7.Vertices.Add(vertex);
    }
    m7.Faces.AddFace(9, 8, 10);
    m7.Faces.AddFace(8, 11, 10);
    m_tree.Add(m7, pth_7);

    i_tree.Add(0, pth_7);
    i_tree.Add(0, pth_7);
    i_tree.Add(0, pth_7);
    i_tree.Add(0, pth_7);

    i_tree.Add(1, pth_7);
    i_tree.Add(1, pth_7);
    i_tree.Add(1, pth_7);
    i_tree.Add(1, pth_7);

    //

    Mesh m8 = new Mesh();
    GH_Path pth_8 = new GH_Path(8);

    foreach (Point3d vertex in vertices)
    {
      m8.Vertices.Add(vertex);
    }
    m8.Faces.AddFace(2, 7, 11);
    m8.Faces.AddFace(2, 4, 7);
    m8.Faces.AddFace(2, 1, 4);
    m8.Faces.AddFace(1, 9, 4);
    m_tree.Add(m8, pth_8);

    i_tree.Add(0, pth_8);
    i_tree.Add(0, pth_8);
    i_tree.Add(1, pth_8);
    i_tree.Add(0, pth_8);

    i_tree.Add(0, pth_8);
    i_tree.Add(1, pth_8);
    i_tree.Add(1, pth_8);
    i_tree.Add(1, pth_8);

    //

    Mesh m9 = new Mesh();
    GH_Path pth_9 = new GH_Path(9);

    foreach (Point3d vertex in vertices)
    {
      m9.Vertices.Add(vertex);
    }
    m9.Faces.AddFace(1, 0, 4);
    m9.Faces.AddFace(1, 4, 5);
    m9.Faces.AddFace(2, 7, 3);
    m9.Faces.AddFace(2, 6, 7);
    m_tree.Add(m9, pth_9);

    i_tree.Add(0, pth_9);
    i_tree.Add(1, pth_9);
    i_tree.Add(0, pth_9);
    i_tree.Add(1, pth_9);

    i_tree.Add(0, pth_9);
    i_tree.Add(1, pth_9);
    i_tree.Add(0, pth_9);
    i_tree.Add(1, pth_9);

    //

    Mesh m10 = new Mesh();
    GH_Path pth_10 = new GH_Path(10);

    foreach (Point3d vertex in vertices)
    {
      m10.Vertices.Add(vertex);
    }
    m10.Faces.AddFace(8, 4, 11);
    m10.Faces.AddFace(4, 1, 11);
    m10.Faces.AddFace(11, 1, 2);
    m10.Faces.AddFace(4, 5, 1);
    m_tree.Add(m10, pth_10);

    i_tree.Add(1, pth_10);
    i_tree.Add(1, pth_10);
    i_tree.Add(0, pth_10);
    i_tree.Add(1, pth_10);

    i_tree.Add(0, pth_10);
    i_tree.Add(1, pth_10);
    i_tree.Add(0, pth_10);
    i_tree.Add(0, pth_10);

    //

    Mesh m11 = new Mesh();
    GH_Path pth_11 = new GH_Path(11);

    foreach (Point3d vertex in vertices)
    {
      m11.Vertices.Add(vertex);
    }
    m11.Faces.AddFace(0, 8, 3);
    m11.Faces.AddFace(7, 1, 11);
    m11.Faces.AddFace(11, 1, 2);
    m11.Faces.AddFace(7, 5, 1);
    m_tree.Add(m11, pth_11);

    i_tree.Add(0, pth_11);
    i_tree.Add(1, pth_11);
    i_tree.Add(0, pth_11);
    i_tree.Add(1, pth_11);

    i_tree.Add(1, pth_11);
    i_tree.Add(1, pth_11);
    i_tree.Add(0, pth_11);
    i_tree.Add(0, pth_11);

    //

    Mesh m12 = new Mesh();
    GH_Path pth_12 = new GH_Path(12);

    foreach (Point3d vertex in vertices)
    {
      m12.Vertices.Add(vertex);
    }
    m12.Faces.AddFace(9, 0, 1);
    m12.Faces.AddFace(3, 11, 2);
    m12.Faces.AddFace(6, 5, 10);
    m12.Faces.AddFace(4, 7, 8);
    m_tree.Add(m12, pth_12);

    i_tree.Add(1, pth_12);
    i_tree.Add(0, pth_12);
    i_tree.Add(1, pth_12);
    i_tree.Add(0, pth_12);

    i_tree.Add(0, pth_12);
    i_tree.Add(1, pth_12);
    i_tree.Add(0, pth_12);
    i_tree.Add(1, pth_12);

    //

    Mesh m13 = new Mesh();
    GH_Path pth_13 = new GH_Path(13);

    foreach (Point3d vertex in vertices)
    {
      m13.Vertices.Add(vertex);
    }
    m13.Faces.AddFace(3, 0, 7);
    m13.Faces.AddFace(0, 10, 7);
    m13.Faces.AddFace(7, 10, 6);
    m13.Faces.AddFace(0, 9, 10);
    m_tree.Add(m13, pth_13);

    i_tree.Add(0, pth_13);
    i_tree.Add(1, pth_13);
    i_tree.Add(1, pth_13);
    i_tree.Add(1, pth_13);

    i_tree.Add(0, pth_13);
    i_tree.Add(0, pth_13);
    i_tree.Add(0, pth_13);
    i_tree.Add(1, pth_13);

    //

    mesh_tree = m_tree;
    bool_patterns = i_tree;
  }
}
  
If you'd like the 14 meshes without anything extra (without inputs, outputs, using statements, etc.) you can copy the code below.
    
	Mesh m0 = new Mesh();
	GH_Path pth_0 = new GH_Path(0);

	foreach (Point3d vertex in vertices)
    {
      m0.Vertices.Add(vertex);
    }
	m0.Faces.AddFace(0, 8, 3);
	m_tree.Add(m0, pth_0);

	i_tree.Add(0, pth_0);
	i_tree.Add(1, pth_0);
	i_tree.Add(1, pth_0);
	i_tree.Add(1, pth_0);

	i_tree.Add(1, pth_0);
	i_tree.Add(1, pth_0);
	i_tree.Add(1, pth_0);
	i_tree.Add(1, pth_0);

    //

	Mesh m1 = new Mesh();
	GH_Path pth_1 = new GH_Path(1);

	foreach (Point3d vertex in vertices)
    {
      m1.Vertices.Add(vertex);
    }
	m1.Faces.AddFace(1, 8, 3);
	m1.Faces.AddFace(1, 9, 8);
	m_tree.Add(m1, pth_1);

	i_tree.Add(0, pth_1);
	i_tree.Add(0, pth_1);
	i_tree.Add(1, pth_1);
	i_tree.Add(1, pth_1);

	i_tree.Add(1, pth_1);
	i_tree.Add(1, pth_1);
	i_tree.Add(1, pth_1);
	i_tree.Add(1, pth_1);

    //

	Mesh m2 = new Mesh();
	GH_Path pth_2 = new GH_Path(2);

	foreach (Point3d vertex in vertices)
    {
      m2.Vertices.Add(vertex);
    }
	m2.Faces.AddFace(0, 8, 3);
	m2.Faces.AddFace(9, 5, 4);
	m_tree.Add(m2, pth_2);

	i_tree.Add(0, pth_2);
	i_tree.Add(1, pth_2);
	i_tree.Add(1, pth_2);
	i_tree.Add(1, pth_2);

	i_tree.Add(1, pth_2);
	i_tree.Add(0, pth_2);
	i_tree.Add(1, pth_2);
	i_tree.Add(1, pth_2);

    //

	Mesh m3 = new Mesh();
	GH_Path pth_3 = new GH_Path(3);

	foreach (Point3d vertex in vertices)
    {
      m3.Vertices.Add(vertex);
    }
	m3.Faces.AddFace(0, 8, 3);
	m3.Faces.AddFace(6, 5, 10);
	m_tree.Add(m3, pth_3);

	i_tree.Add(0, pth_3);
	i_tree.Add(1, pth_3);
	i_tree.Add(1, pth_3);
	i_tree.Add(1, pth_3);

	i_tree.Add(1, pth_3);
	i_tree.Add(1, pth_3);
	i_tree.Add(0, pth_3);
	i_tree.Add(1, pth_3);

    //

	Mesh m4 = new Mesh();
	GH_Path pth_4 = new GH_Path(4);

	foreach (Point3d vertex in vertices)
    {
      m4.Vertices.Add(vertex);
    }
	m4.Faces.AddFace(0, 9, 3);
	m4.Faces.AddFace(3, 9, 11);
	m4.Faces.AddFace(11, 9, 10);
	m_tree.Add(m4, pth_4);

	i_tree.Add(0, pth_4);
	i_tree.Add(1, pth_4);
	i_tree.Add(1, pth_4);
	i_tree.Add(1, pth_4);

	i_tree.Add(0, pth_4);
	i_tree.Add(0, pth_4);
	i_tree.Add(0, pth_4);
	i_tree.Add(0, pth_4);

    //

	Mesh m5 = new Mesh();
	GH_Path pth_5 = new GH_Path(5);

	foreach (Point3d vertex in vertices)
    {
      m5.Vertices.Add(vertex);
    }
	m5.Faces.AddFace(3, 1, 8);
	m5.Faces.AddFace(1, 9, 8);
	m5.Faces.AddFace(7, 6, 11);
	m_tree.Add(m5, pth_5);

	i_tree.Add(0, pth_5);
	i_tree.Add(0, pth_5);
	i_tree.Add(1, pth_5);
	i_tree.Add(1, pth_5);

	i_tree.Add(1, pth_5);
	i_tree.Add(1, pth_5);
	i_tree.Add(1, pth_5);
	i_tree.Add(0, pth_5);

    //

	Mesh m6 = new Mesh();
	GH_Path pth_6 = new GH_Path(6);

	foreach (Point3d vertex in vertices)
    {
      m6.Vertices.Add(vertex);
    }
	m6.Faces.AddFace(1, 9, 0);
	m6.Faces.AddFace(6, 5, 10);
	m6.Faces.AddFace(2, 3, 11);
	m_tree.Add(m6, pth_6);

	i_tree.Add(1, pth_6);
	i_tree.Add(0, pth_6);
	i_tree.Add(1, pth_6);
	i_tree.Add(0, pth_6);

	i_tree.Add(1, pth_6);
	i_tree.Add(1, pth_6);
	i_tree.Add(0, pth_6);
	i_tree.Add(1, pth_6);

    //

	Mesh m7 = new Mesh();
	GH_Path pth_7 = new GH_Path(7);

	foreach (Point3d vertex in vertices)
    {
      m7.Vertices.Add(vertex);
    }
	m7.Faces.AddFace(9, 8, 10);
	m7.Faces.AddFace(8, 11, 10);
	m_tree.Add(m7, pth_7);

	i_tree.Add(0, pth_7);
	i_tree.Add(0, pth_7);
	i_tree.Add(0, pth_7);
	i_tree.Add(0, pth_7);

	i_tree.Add(1, pth_7);
	i_tree.Add(1, pth_7);
	i_tree.Add(1, pth_7);
	i_tree.Add(1, pth_7);

    //

	Mesh m8 = new Mesh();
	GH_Path pth_8 = new GH_Path(8);

	foreach (Point3d vertex in vertices)
    {
      m8.Vertices.Add(vertex);
    }
	m8.Faces.AddFace(2, 7, 11);
	m8.Faces.AddFace(2, 4, 7);
	m8.Faces.AddFace(2, 1, 4);
	m8.Faces.AddFace(1, 9, 4);
	m_tree.Add(m8, pth_8);

	i_tree.Add(0, pth_8);
	i_tree.Add(0, pth_8);
	i_tree.Add(1, pth_8);
	i_tree.Add(0, pth_8);

	i_tree.Add(0, pth_8);
	i_tree.Add(1, pth_8);
	i_tree.Add(1, pth_8);
	i_tree.Add(1, pth_8);

    //

	Mesh m9 = new Mesh();
	GH_Path pth_9 = new GH_Path(9);

	foreach (Point3d vertex in vertices)
    {
      m9.Vertices.Add(vertex);
    }
	m9.Faces.AddFace(1, 0, 4);
	m9.Faces.AddFace(1, 4, 5);
	m9.Faces.AddFace(2, 7, 3);
	m9.Faces.AddFace(2, 6, 7);
	m_tree.Add(m9, pth_9);

	i_tree.Add(0, pth_9);
	i_tree.Add(1, pth_9);
	i_tree.Add(0, pth_9);
	i_tree.Add(1, pth_9);

	i_tree.Add(0, pth_9);
	i_tree.Add(1, pth_9);
	i_tree.Add(0, pth_9);
	i_tree.Add(1, pth_9);

    //

	Mesh m10 = new Mesh();
	GH_Path pth_10 = new GH_Path(10);

	foreach (Point3d vertex in vertices)
    {
      m10.Vertices.Add(vertex);
    }
	m10.Faces.AddFace(8, 4, 11);
	m10.Faces.AddFace(4, 1, 11);
	m10.Faces.AddFace(11, 1, 2);
	m10.Faces.AddFace(4, 5, 1);
	m_tree.Add(m10, pth_10);

	i_tree.Add(1, pth_10);
	i_tree.Add(1, pth_10);
	i_tree.Add(0, pth_10);
	i_tree.Add(1, pth_10);

	i_tree.Add(0, pth_10);
	i_tree.Add(1, pth_10);
	i_tree.Add(0, pth_10);
	i_tree.Add(0, pth_10);

    //

	Mesh m11 = new Mesh();
	GH_Path pth_11 = new GH_Path(11);

	foreach (Point3d vertex in vertices)
    {
      m11.Vertices.Add(vertex);
    }
	m11.Faces.AddFace(0, 8, 3);
	m11.Faces.AddFace(7, 1, 11);
	m11.Faces.AddFace(11, 1, 2);
	m11.Faces.AddFace(7, 5, 1);
	m_tree.Add(m11, pth_11);

	i_tree.Add(0, pth_11);
	i_tree.Add(1, pth_11);
	i_tree.Add(0, pth_11);
	i_tree.Add(1, pth_11);

	i_tree.Add(1, pth_11);
	i_tree.Add(1, pth_11);
	i_tree.Add(0, pth_11);
	i_tree.Add(0, pth_11);

    //

	Mesh m12 = new Mesh();
	GH_Path pth_12 = new GH_Path(12);

	foreach (Point3d vertex in vertices)
    {
      m12.Vertices.Add(vertex);
    }
	m12.Faces.AddFace(9, 0, 1);
	m12.Faces.AddFace(3, 11, 2);
	m12.Faces.AddFace(6, 5, 10);
	m12.Faces.AddFace(4, 7, 8);
	m_tree.Add(m12, pth_12);

	i_tree.Add(1, pth_12);
	i_tree.Add(0, pth_12);
	i_tree.Add(1, pth_12);
	i_tree.Add(0, pth_12);

	i_tree.Add(0, pth_12);
	i_tree.Add(1, pth_12);
	i_tree.Add(0, pth_12);
	i_tree.Add(1, pth_12);

    //

	Mesh m13 = new Mesh();
	GH_Path pth_13 = new GH_Path(13);

	foreach (Point3d vertex in vertices)
    {
      m13.Vertices.Add(vertex);
    }
	m13.Faces.AddFace(3, 0, 7);
	m13.Faces.AddFace(0, 10, 7);
	m13.Faces.AddFace(7, 10, 6);
	m13.Faces.AddFace(0, 9, 10);
	m_tree.Add(m13, pth_13);

	i_tree.Add(0, pth_13);
	i_tree.Add(1, pth_13);
	i_tree.Add(1, pth_13);
	i_tree.Add(1, pth_13);

	i_tree.Add(0, pth_13);
	i_tree.Add(0, pth_13);
	i_tree.Add(0, pth_13);
	i_tree.Add(1, pth_13);