Remove a list of Triangle Indices from triangles

I have a list of triangle indices that I want to delete. This is given as

int i0 = triangles[triangleIndex * 3 + 0]; int i1 = triangles[triangleIndex * 3 + 1]; int i2 = triangles[triangleIndex * 3 + 2];

This method works to delete a single triangle index, but it does not work with consecutive list of triangle indices:

int[] triangles = meshFilter.sharedMesh.triangles;
void DeleteTriangle(int triangleIndex)
    {
        Mesh newMesh = meshFilter.sharedMesh;
        List<int> m_triangles = new List<int>();
        m_triangles.AddRange(triangles);

        m_triangles.RemoveAt(triangleIndex * 3);
        m_triangles.RemoveAt(triangleIndex * 3);
        m_triangles.RemoveAt(triangleIndex * 3);

        newMesh.triangles = m_triangles.ToArray();
    }

Check out the solution from the very knowledgeable Kurt-Dekker here. Sounds like a very similar problem.

but it does not work with consecutive list of triangle indices:

So what does your code for that looks like? You posted code that does work and you claim you have code that does not work but you haven’t shown that code. So what kind of answer do you expect from us? Writing the code for you? Of course when you remove multiple triangles you have to keep in mind that when you remove a triangle, all following triangles would move down one place. So the best approach is to remove the largest triangle index first. So if you have a list or array of triangle indices, sort them from the largest to the smallest index. Then the removing would work just fine.

Though as Kurt recommends, it’s also possible to just create a new list of triangles, go through your old list of triangles and copy over those you want to keep. That way you do not modify the original array / list so your triangle indices would still match the source array.