- Home /
How can I remove redundant vertices in custom mesh?
Hi, I've been working on a voxel-based model builder to create assets and characters for my voxel-based game. It has been working rather well so far, however I recently encountered an error with the amount of vertices in the model.
I was working on a model larger than my previous attempts, and I had almost finished when suddenly it disappeared and Unity threw a Mesh.vertices too large exception. I realized that with each voxel/block I was placing there was obviously a heap of vertices to go with it and that it was going to prevent me from building the size of objects I required.
And so I am looking for a solution that will allow me to reduce the amount of vertices in the models I create. One theory I have is somehow figuring out which faces are part of a larger face (i.e 4 squares alligned that make up a larger square) and then removing the vertices in the middle to create a larger face/triangles from the remaining corner vertices. I have no idea how to do this!
Simply ask for any pictures or code snippets that will be needed and I'll try and provide them as soon as I can. Thank you!
Are you creating these models programmatically (by generating vertex and index arrays) or are you modelling them in external software?
If former, I recommend latter. You're talking about selective edge removal on co-planar surfaces. That's insanely complex.
I would recommend doing that in 3D software - in 3DS $$anonymous$$ax for example, to remove unnecessary edges, simply go into Edge edit more, select edge you want removed, and hit Backspace to remove only the edge, or Ctrl+Backspace to remove both the edge and it's for$$anonymous$$g vertices.
If you're talking about generating $$anonymous$$inecraft-alike environments from cubes and just want to optimize your world, then it's a different situation, which you cannot approach by removing edges from flat surfaces since different blocks use different textures (materials). Ins$$anonymous$$d, you need to only generate the surface blocks and then cull the sides of the cube that are not exposed (cannot be seen anyway). This also requires re-generating those sides when they will be seen, such as moving a neighbour block. Tons of articles on those approaches.
Sorry for being vague. Yes i am using programmatically created meshes by specifying vertices and triangles that make up the objects. I would use an external program but this just happens to be the only way it will work for my particular application. I will look into greedy mesh algorithms and update back on here. Thank you so much for all of your replies! :)
Greedy mesh algorithms is probably the way to go. That being said, if you have some additional information about your meshes, you might be able to create something better/faster/easier than a generalized algorithm.
Example: I built some walls from quads, and figured that I should combine the entire wall into one mesh. Since I knew that the quads were all at the same height, and rotated one out of eight directions, I could pretty easily find continous walls of quads, discard every piece but the end pieces, and then create a new mesh from the furthermost verts of those meshes. A generalized algorithm would have worked, but it would probably have taken a lot more time to implement.
If your vert positions follow some kind of grid, or you know something specific about the rotations of your faces, you could do something similar.
Your answer
![](https://koobas.hobune.stream/wayback/20220612033102im_/https://answers.unity.com/themes/thub/images/avi.jpg)