/** * \brief Collapses all passed indices to a single shared index. * */ public static bool MergeVertices(this pb_Object pb, int[] indices) { Vector3[] verts = pb.vertices; Vector3 cen = Vector3.zero; foreach (int i in indices) { cen += verts[i]; } cen /= (float)indices.Length; pb_IntArray[] sharedIndices = pb.sharedIndices; int newIndex = pb_IntArrayUtility.MergeSharedIndices(ref sharedIndices, indices); pb.SetSharedIndices(sharedIndices); int firstTriInSharedIndexArr = pb.sharedIndices[newIndex][0]; pb.SetSharedVertexPosition(firstTriInSharedIndexArr, cen); int[] mergedSharedIndex = pb.GetSharedIndices()[newIndex].array; int[] removedIndices = pb.RemoveDegenerateTriangles(); // get a non-deleted index to work with int ind = -1; for (int i = 0; i < mergedSharedIndex.Length; i++) { if (!removedIndices.Contains(mergedSharedIndex[i])) { ind = mergedSharedIndex[i]; } } int t = ind; for (int i = 0; i < removedIndices.Length; i++) { if (ind > removedIndices[i]) { t--; } } pb.ClearSelection(); if (t > -1) { pb.SetSelectedTriangles(new int[1] { t }); } return(true); }