Hi @clement,
Thank you for trying to help. It seems I have another problem to solve before I can follow your advice in detail.
Problem is that, if I do not run the command m.Vertices.CombineIdentical(...);
on the mesh after constructing it, my code only returns an invalid mesh, and thus I can’t bake it. And if I run the command then I suppose this can be the cause to why any disjoint edges/vertices disappears (?).
But I have no idea why the mesh becomes invalid in the first place. I do define new faces with CCW winding, and I get no hints about why it’s not valid, and I can’t even investigate without being able to bake the mesh. Sigh.
This is what I do to the mesh after constructing it, otherwise it returns an invalid mesh :
protected void RemoveFaces(Mesh m, List<int> facesIndexesToRemove, bool DoCombineVertices = true)
{
var noDupes = facesIndexesToRemove.Distinct().OrderByDescending(x => x);
m.Faces.DeleteFaces(noDupes);
if (DoCombineVertices)
m.Vertices.CombineIdentical(false, false);
m.Normals.ComputeNormals();
m.Compact();
}
// Rolf
Edit:
Example of code that constructs faces “below” the split-line (split-edge is between A & D). Also the A and D vertices are duplicated before calling this method.
private void MakeFaces2(Mesh m, int pt_A, int pt_B, int pt_C, int pt_D, ref int[] newFaces)
{
/*
* Finding Shortest diagonal
*
* A D
* _________
* / \ \
* / \ \
* / \ \
* -----------------
* B C/V
*/
var ptA = m.Vertices[pt_A];
var ptB = m.Vertices[pt_B];
var ptC = m.Vertices[pt_C];
var ptD = m.Vertices[pt_D];
if (ptA.DistanceTo(ptC) < ptD.DistanceTo(ptB))
{
// newFaces[0] = upper triangle
newFaces[1] = m.Faces.AddFace(pt_D, pt_A, pt_C);
newFaces[2] = m.Faces.AddFace(pt_C, pt_A, pt_B);
}
else
{
// newFaces[0] = upper triangle
newFaces[1] = m.Faces.AddFace(pt_D, pt_A, pt_B);
newFaces[2] = m.Faces.AddFace(pt_B, pt_C, pt_D);
}
}