NGon Unweld


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();
            .Select(ngon => mesh.DuplicateMesh().Faces.ExtractFaces(ngon.FaceIndexList().Select(i => unchecked((int)i)))));
    return Result.Success;
} (99.5 KB)


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);

    A = explodedMesh;