- Home /
Remove unnecessary vertices from plane mesh
I have a horizontal planar mesh that I believe could be reduced in polys (illustrative example of before and possible after below --all vertices have the same y value).
My approach so far would be to do this:
var vertices = mesh.vertices;
foreach (var vertex in vertices)
{
if (isVertexOnEdgeOfMesh(vertex, mesh)) continue;
var connectingVertices = GetConnectingVertices(vertex, mesh);
var removable = true;
foreach (var connectingVertex in connectingVertices)
{
if (vertex.y == connectingVertex.y) continue;
removable = false;
break;
}
if (removable)
{
//remove vertex here
}
}
The idea is to remove any vertex that is not on an edge, and that also shares the same y value with all of its neighbors.
I'm not sure if this is even the right approach, but even if it is, I don't know how to remove the vertex without screwing up the triangles in the mesh. I don't see any reason why this type of thing shouldn't be possible, give the layout of the mesh, but maybe I'm missing something?
The two easiest approaches depending on how you are using the plane:
1) Use the CreatePlane editor script. This script allow you to set the number of divisions, so if you want a two-triangle plane, you can create one.
2) If your plane is for vertical use, use Unity Quad game object ins$$anonymous$$d. It is a two triangle plane.
Finally if you want to create the plane in code, it would likely be easier to create the whole plane from scratch rather than trying to edit existing planes. If you hunt around, you will find a number of examples of scripts for creating planes.
the mesh is joined from a bunch of plane meshes of all the same width and height. the plane meshes have either 2 tris (1x1) or 8 tris (2x2) the final mesh isn't necessarily a square but its width/height is based of the number of plane meshes it was originally composed of.
Answer by Benjames · Mar 05, 2015 at 06:15 PM
I had a question similar to this and I ended up answering it my self.
heres the link: http://answers.unity3d.com/questions/586474/mesh-simplification-for-marching-cubes-algorithm.html
I will maybe repost an edit with some details on how i did it, right now all I remember is that is was in some sorta backwards way.
Mainly nobody has posted on this question for two years so Im not sure if still need an answer.