Mesh Recursion



Sorry for unusual aspect ratio, this video was originally made for my instagram account .

Testing “Vertex Color Texture” in vray 5 for Grasshopper. 1500 frames, ~12 hours, 2x Intel Xeon E5-2630 v4 2.20GHz
Music: Lone Harvest by Kevin MacLeod, http://incompetech.com

private void RunScript(Mesh mesh, double level, List<double> factors, ref object A)
{
  for (var k = 0; k < level; k++)
  {
    var d = level - k > 1.0 ? 1.0 : level - k;
    var meshes = new List<Mesh>();
    for (var i = 0; i < mesh.Faces.Count; i++)
    meshes.Add(SubdivideFace(mesh, i, d * factors[k]));
    mesh = new Mesh();
    mesh.Append(meshes);
    mesh.RebuildNormals();
  }
  A = mesh;
}
// <Custom additional code> 
private static readonly MeshFace[] Tri =
{
  new MeshFace(1, 3, 0),
  new MeshFace(2, 3, 1),
  new MeshFace(0, 3, 2)
};

private static readonly MeshFace[] Quad =
{
  new MeshFace(1, 4, 0),
  new MeshFace(2, 4, 1),
  new MeshFace(3, 4, 2),
  new MeshFace(0, 4, 3)
};
private static Mesh SubdivideFace(Mesh m, int i, double d)
{
  var mf = m.Faces[i];
  var vertices = new List<Point3d>();
  for (var j = 0; j < (mf.IsQuad ? 4 : 3); j++)
      vertices.Add(m.Vertices[mf[j]]);
  var normal = new Vector3d(m.FaceNormals[i]) * d;
  var center = m.Faces.GetFaceCenter(i) + normal;
  vertices.Add(center);
  var o = new Mesh();
  o.Vertices.AddVertices(vertices);
  o.Faces.AddFaces(mf.IsQuad ? Quad : Tri);
  return o;
}
// </Custom additional code> 


MeshRecursion.gh (9.0 KB)

21 Likes

The music is a nice touch! :slight_smile:

1 Like