PlanktonMesh/C# Get adjacent Face Center

Hi all,

I am trying to figure out how to connect some FaceCenters of a PlanktonMesh.

I couldnt figure it out yet, and cant find many examples about PlanktonMesh in the scripting component.

My future aim would be connect the faceCenters to a dual graph.

I found this thread on github and asked but nobody answered Face Adjacency · Issue #41 · meshmash/Plankton · GitHub

Here the ghFile:pmMeshF.gh (4.6 KB)

Maybe here somebody could help me.

Also in general I am really interested in moreexapmles of the use of the PlanktonLibrary.

Thanks and a nice day!

Hi Baris, here’s a simple script for creating a dual mesh using Plankton… Hope it helps!

// convert the input Rhino mesh to a Plankton mesh 
var pmesh = x.ToPlanktonMesh();

// create a new, empty Plankton mesh
var dual = new PlanktonMesh();

// add a vertex to the dual for every face of the input mesh
for (int i = 0; i < pmesh.Faces.Count; i++)
{
  var fc = pmesh.Faces.GetFaceCenter(i);
  dual.Vertices.Add(fc.X, fc.Y, fc.Z);
}

// add a face to the dual for every interior vertex of the input mesh
for (int i = 0; i < pmesh.Vertices.Count; i++)
{
  // skip boundary vertices (require special rules)
  if (pmesh.Vertices.IsBoundary(i))
    continue;

  // create a face from the neighbouring faces of each vertex
  dual.Faces.AddFace(pmesh.Vertices.GetVertexFaces(i));
}

// output
A = dual;
3 Likes

Thanks a lot @will!

1 Like

Hi @will and @Baris how can I take the advantage of the PlanktonMesh for dualmesh but at the end generate a mesh with nGons faces?

Hi Thomas,
The little script here can be used to convert a polygon or list of points into ngons, and could easily be tagged onto the end of a script using Plankton

Back when me and @will wrote Plankton, there were no ngons in Rhino, which was one of the reasons we wrote it. It could probably do with a little update now to include conversion to and from Rhino ngon meshes. Rhino ngons are a little different (actually collections of adjacent triangles) to those in Plankton (where all faces can have any number of sides, so ngons aren’t a different type from triangles or quads). It’s certainly possible to convert between them though.

1 Like
using KPlankton;

    var pmesh = x.ToKPlanktonMesh();
    var M = new Mesh();

    for (int i = 0; i < pmesh.Faces.Count; i++)
    {
      var fc = pmesh.Faces.GetFaceCenter(i);
      M.Vertices.Add(fc.X, fc.Y, fc.Z);
    }
    for (int i = 0; i < pmesh.Vertices.Count; i++)
    {
      if (pmesh.Vertices.IsBoundary(i)) continue;

      int center = M.Vertices.Add(pmesh.Vertices[i].ToPoint3f());
      var indices = pmesh.Vertices.GetVertexFaces(i);
      var ngonFaces = new List<int>();

      for(int j = 0;j < indices.Length;j++)
        ngonFaces.Add(M.Faces.AddFace(indices[(j + 1) % indices.Length], indices[j], center));
      var ngon = MeshNgon.Create(indices, ngonFaces);
      if (null != ngon)M.Ngons.AddNgon(ngon);
    }
    M.RebuildNormals();

I had to invert the order of the vertices when creating the faces to avoid flipping the mesh.

Thank you @DanielPiker, I saw in some of your codes you are only using KPlankton.
I suposse that now is part of Kangaroo and only that is updated in the future? or what are the plans?

1 Like

Good spot on the ordering.
KPlankton is just a copy of Plankton. Several Kangaroo components use it internally, so it needed to be included, but while avoiding name conflicts for people with a separate installation of Plankton.

1 Like