Ngons rhino wip

Hi,

I am new to rhino wip rhino-common but I would really like to test new ngon functionality.

What I would like to do is to create simple mesh let say with 5 vertices and get information about adjacency of faces adjacent to edges.

Thank you.

Here is a mesh with ngons that you can try: Dodecahedron.3dm (34.2 KB)

This block of code should be able to make one:

/// <summary>
/// Creates a planar mesh from a closed, planar polyline curve
/// </summary>
public static Mesh MeshFromPolyline(PolylineCurve curve)
{
  Mesh mesh = null;

  if (null != curve && 
      curve.IsClosed && 
      curve.IsPlanar() && 
      curve.PointCount >= 4
      )
  {
    if (4 == curve.PointCount)
    {
      mesh = new Mesh();
      var a = mesh.Vertices.Add(curve.Point(0));
      var b = mesh.Vertices.Add(curve.Point(1));
      var c = mesh.Vertices.Add(curve.Point(2));
      mesh.Faces.AddFace(a, b, c);
    }
    else if (5 == curve.PointCount)
    {
      mesh = new Mesh();
      var a = mesh.Vertices.Add(curve.Point(0));
      var b = mesh.Vertices.Add(curve.Point(1));
      var c = mesh.Vertices.Add(curve.Point(2));
      var d = mesh.Vertices.Add(curve.Point(3));
      mesh.Faces.AddFace(a, b, c, d);
    }
    else
    {
      mesh = Mesh.CreateFromClosedPolyline(curve.ToPolyline());
      if (null != mesh)
      {
        var vertices = new List<int>(mesh.Vertices.Count);
        for (var vi = 0; vi < mesh.Vertices.Count; vi++)
          vertices.Add(vi);

        var faces = new List<int>(mesh.Faces.Count);
        for (var fi = 0; fi < mesh.Faces.Count; fi++)
          faces.Add(fi);

        var ngon = MeshNgon.Create(vertices.ToArray(), faces.ToArray());
        if (null != ngon)
          mesh.Ngons.AddNgon(ngon);
      }
    }

    if (null != mesh)
    {
      mesh.FaceNormals.ComputeFaceNormals();
      mesh.Normals.ComputeNormals();
      mesh.Compact();
      if (!mesh.IsValid)
        mesh = null;
    }
  }

  return mesh;
}

– Dale

1 Like

Thank you for a reply.

Do N-Gons have any adjacency information to other ngons?

How should I find all ngons that are adjacent to one of the ngon?
Do ngons know about each other? I tried to look into mesh edges, vertices and faces, they do not have any property to get connected ngon or similar.

To specify my question about adjacency I was going through documentation and could not find this:

This is only face - face adjacency. Maybe @dale has a better advice on this, but this works too, I have not sorted out Mesh Edge - To Ngon and vertex To Ngon relation, and also do not know what happens when mesh face or ngon is deleted, but this works when ngons are just initialized:

Adjacency
Iterate over mesh faces in ngon and get connected faces
if that face does not belong to the same ngon add to adjacency list

        List<int>[] faceAdj = new List<int>[mymesh.Ngons.Count];

        for (int i = 0; i < mymesh.Ngons.Count; i++) 
        {

            List<int> faceAdjTemp = new List<int>();
            uint[] meshFaceIdInCurrentNGon = mymesh.Ngons[i].FaceIndexList();

            for (int j = 0; j < meshFaceIdInCurrentNGon.Length; j++) 
            {
             int[] id = mymesh.Faces.AdjacentFaces((int)meshFaceIdInCurrentNGon[j]); 

              for (int k = 0; k < id.Length; k++) 
                {
                    int ngonID = mymesh.Ngons.NgonIndexFromFaceIndex(id[k]);

                    if (ngonID != i && !faceAdjTemp.Contains(ngonID)) 
                        faceAdjTemp.Add(ngonID);
                }
            }
            faceAdj[i] = faceAdjTemp; 
        }

But I agree it would be nice if ngons have some adjacency properties within each other