- Home /

# delete specific triangles / polygons in a mesh

Hello,

I have a specific problem that I don't know how to achieve. I've looked through the Mesh class documentation but I didn't get it.

I have a simple mesh, like a road really. It's basically a row of triangles similar as in the illustration. I need to interrupt that row by deleting polygons according to the position of some marker game objects. Here's the image:

I think I know how to find the vertices that are closest to to the markers. but I don't understand how to find the right triangles and how to remove them. The fact that this mesh will be split into two parts afterwards seems to be making this problem even more complicated.

Thanks for reading and I hope someone can help.

**Answer** by hexagonius
·
May 17, 2018 at 08:38 PM

There's two arrays of interest. one containing the vertex positions in localspace and one containing indices into that array, as a magnitude of 3, that basically describes which vertices go into which triangle. The order of those also describes which direction the surface normal is facing, where clockwise is facing backwards and counterclockwise is forward.

This whole chapter about Meshes describes all aspects in more detail.

What you basically need to do is finding out which vertices are the ones you want to delete, which of these also go into other triangles than the ones you're about to remove, exclude them and rewrite the two arrays, vertices and indices without the missing ones.

If you're talking about a mesh split, of course you need to generate the remaining vertices into two new sets of arrays.

The indexing array is exactly 3 times the vertices array, so whichever vertex you find, its index position in the indexing array tells you which triangle it belongs to (index 4 would be the second vertex of the second triangle)

Thank you Hexagonius! I understood everything until splitting the mesh. I don't really want to split it into two separate meshes/objects. It should still be a single mesh with two parts. As you can see in the image above, those two parts are not connected. I understood there is only one vertex and one triangle array in Mesh class, so that's confusing. If I put all the vertices (both from the left part and the right part) into one array, Unity will connect the parts. How can we have two vertex arrays in a single Mesh?

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

How to add vertex points to a mesh 1 Answer

Quick way to get touching triangles? 0 Answers

Mesh triangles don't match wireframe view? 0 Answers

Vertex triangles 0 Answers