- 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 $$anonymous$$esh 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 $$anonymous$$esh?
Answer by BergOnTheJob · Jul 10, 2020 at 04:27 PM
Hey @wlad_s,
i know its been a while, but if this helps, this tool set can delete specific triangles / polygons in a mesh.
https://assetstore.unity.com/packages/slug/166155
It also has a bunch of other tools for modeling in Unity.
Oh wow! That's an amazing tool! Thanks! I actually needed a specific solution that would automatically work on lots of meshes by pressing one button. I've solved this problem a long time ago and have garnered much knowledge about editing meshes through scripts in the meantime. I can't even imagine how much hard work has gone into building that Oasis Editor. Congrats if you're the one who made it!
You're too kind, Thank you so much @wlad_s ! I created the editor all by my lonesome and it did take several months. I haven't been able to find work since the COVID outbreak in $$anonymous$$arch, so I decided to release my own software to support my family. If you have any C# Unity questions or need help creating something you can always reach me at OasisRoboticsInc@gmail.com. I got my degree in 3d computer animation 15 years ago and have been doing game development in Unity since 2013.
Thanks again! - Aaron
Aaron Bergquist Certified Unity Programmer
Your answer
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