Hi everyone,
as the title says, after using the CombineIdentical method the mesh becomes invalid.
Does someone know why?
Here is my code:
private void RunScript(List<Polyline> plines, ref object A)
{
var mm = new Mesh();
for (int pl = 0; pl < plines.Count; pl++)
{
Line[] lines = plines[pl].GetSegments();
Point3d center = plines[pl].CenterPoint();
Mesh mesh = new Mesh();
mesh.Vertices.Add(center);
mesh.Vertices.AddVertices(plines[pl]);
var faces = new List<int>();
var vertices = new List<int>();
for (int i = 0; i < lines.Length; i++)
{
mesh.Faces.AddFace(0, i + 1, i + 2);
faces.Add(i);
vertices.Add(i);
}
mesh.Ngons.AddNgon(MeshNgon.Create(faces, vertices));
mm.Append(mesh);
}
CleanMesh(mm);
A = mm;
}
// <Custom additional code>
public void CleanMesh(Mesh mesh)
{
mesh.Vertices.CombineIdentical(true, true);
mesh.Vertices.CullUnused();
mesh.Weld(Math.PI);
mesh.FaceNormals.ComputeFaceNormals();
mesh.Normals.ComputeNormals();
if (mesh.SolidOrientation() == -1)
mesh.Flip(true, true, true);
mesh.Compact();
}
// </Custom additional code>
}
File: 20201031_InvalidMesh.gh (4.9 KB)
Thanks for looking at it!
Have a nice weekend everybody!