Construct a disjointed Mesh from a Vertice array

Hi all,

I have a disjointed Mesh with its values broken down into Arrays.
I found out that I couldn’t reconstruct them back to a mesh with the below codes. What is missing here?
@menno @dale ?

        public int[] Faces;
        public float[] Vertices;
        public Vector3f[] FaceNormals;
        public Vector3f[] VertexNormals;

        public Mesh ReconstructMesh()
        {
            var mesh = new Mesh();
            for (int i = 0; i < Vertices.Count()/3; i++)
                mesh.Vertices.Add(new Point3f(Vertices[i * 3], Vertices[i * 3 + 1], Vertices[i * 3 + 2]));

            for (int i = 0; i < Faces.Count() / 3; i++)
                mesh.Faces.AddFace(new MeshFace(Faces[i * 3], Faces[i * 3 + 1], Faces[i * 3 + 2]));
            for (int i = 0; i < FaceNormals.Count(); i++)
                mesh.FaceNormals.AddFaceNormal(FaceNormals[i]);
            for (int i = 0; i < VertexNormals.Count(); i++)
                mesh.Normals.Add(VertexNormals[i]);
            return mesh;
        }

You can use the following to see what is going on. Your code looks good, so maybe the input is faulty?

if (!mesh.IsValidWithLog(out string error))
  RhinoApp.WriteLine(error);
1 Like

Thanks! I will try that out tonight!
It only happens with disjointed mesh. I will try to debug it myself if there’s no apparent error in the codes.