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;
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.
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?
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.