/////////////////////////////////////////////////////////////////////////// #region [Merge} /** * Add all vertices/edges/faces from another mesh, and fix attributes if * needed. * Overriding attributes: vertex's id (of the first mesh only) */ public static void Merge(BMesh mesh, BMesh other) { var newVerts = new Vertex[other.vertices.Count]; int i = 0; foreach (Vertex v in other.vertices) { newVerts[i] = mesh.AddVertex(v.point); AttributeLerp(mesh, newVerts[i], v, v, 1); // copy all attributes v.id = i; ++i; } foreach (Edge e in other.edges) { mesh.AddEdge(newVerts[e.vert1.id], newVerts[e.vert2.id]); } foreach (Face f in other.faces) { var neighbors = f.NeighborVertices(); var newNeighbors = new Vertex[neighbors.Count]; int j = 0; foreach (var v in neighbors) { newNeighbors[j] = newVerts[v.id]; ++j; } mesh.AddFace(newNeighbors); } }