NGon Unweld

Hi,

Is there a way to change mesh normals as if it would be unwelded without destroying NGon preview?
In the image below, on the right side there is a welded mesh and the moment I unweld the mesh all triangulation appears but the shading is as I want:

Export.3dm (194.8 KB)

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    var rc = RhinoGet.GetMultipleObjects("Select Mesh", false, ObjectType.Mesh, out var objRefs);
    if (rc != Result.Success) return rc;
    foreach (var objRef in objRefs)
    {
        var mesh = objRef.Mesh();
        var oMesh = new Mesh();
        oMesh.Append(mesh.GetNgonAndFacesEnumerable()
            .Select(ngon => mesh.DuplicateMesh().Faces.ExtractFaces(ngon.FaceIndexList().Select(i => unchecked((int)i)))));
        oMesh.RebuildNormals();
        doc.Objects.AddMesh(oMesh);
    }
    return Result.Success;
}

UnweldNgonMesh.zip (99.5 KB)

1 Like

Very neat, thank you;)

I going through each Linq expression, does it mean that per each NGon face you are duplicating the whole mesh to extract a face? If yes it is possible to duplicate only selected faces?
I was trying to do this on extracted mesh but this wont work:
Mesh NGonFaceMesh = m.Faces.ExtractFaces(meshFaceList).DuplicateMesh();

Another question why there is a keyword unchecked for casting uint to int array?

  private void RunScript(Mesh m, object y, ref object A)
  {


    Mesh explodedMesh = new Mesh();
    IEnumerable<MeshNgon> ngonFaces = m.GetNgonAndFacesEnumerable();
    
    foreach(MeshNgon ngon in ngonFaces) {
      int[] meshFaceList = ngon.FaceIndexList().Select(j => unchecked((int) j)).ToArray();
      Mesh NGonFaceMesh = m.DuplicateMesh().Faces.ExtractFaces(meshFaceList);
      explodedMesh.Append(NGonFaceMesh);
    }
    
    explodedMesh.RebuildNormals();


    A = explodedMesh;
  }