- Home /
merge vertices at runtime?
is it possible to merge vertices at runtime? I'm aware of stitchscape, however, I'm not trying to merge terrain segments.
I have a preset number of tiles for an environment, that after the script I have chooses which ones to place, I would then like the ability to merge the verts at each face/side of each tile to get one seamless mesh WITH MERGED VERTICES(not the combineChildren method that just combines meshes).
Is anyone aware of how, or if this is possible in unity AT RUNTIME?
I'm looking for something similar at the moment. Ideally a script that already exists. Does anyone know if there is one?
Answer by Brian-Kehrer · Jan 23, 2011 at 05:35 PM
Sure, but you'll need to do it yourself.
Take a look at the Mesh class.
It will work something like this
- Get all meshes you want to combine
- Extract relevant mesh data (verts, normals, UVs whatever)
- Combine mesh data into new arrays
- Loop through combined verts, and check to see if any overlap
- Flag overlapping verts and remove them from all arrays, in the case of triangles, you'll have to be careful.
This certainly isn't easy, and depending on your requirements, there are quite a few different ways of doing this.
In a case where I needed to merge verts before, I trimmed all the float values of the vertices, and added them to a dictionary, keyed on vertex position, and set to return the index. That way, when overlapping verts were added, the old verts were overwritten. You could then look up into the dictionary based on position to retrieve the index. Again, there is a fair amount of complexity there which I'm skimming over, but hopefully you get the idea.
just the answer I was looking for! You wouldn't happen to know of any example/reference scripts anywhere online that could help me understand the details of your post would you? If so I'd be most appreciative. Thanks again