- Home /
How to Move Vertices from a Mesh to a Specific Location
I have a dynamic mesh that is mostly comprised of rectangles. So far, the actual system has gone smoothly. I'm getting to a stage where I want to start polishing the actual meshes off, and the topology is part of that. As I have it now, the meshes aren't able to be placed exactly. That is, there is a gap between the meshes--a very minuscule one at that.
In the past, I've done similar things outside of Unity. Basically, what I'm looking to do specifically is move a vertex near another vertex so that they are at exactly the same position. At the moment, I've already implemented a spatial hashing algorithm that can sort the hashed vertices into buckets and then I can get similar vertices by iterating over the buckets. However, I'm stuck at the part of actually determining and moving the vertices into their exact locations.
I'm assuming that I need to somehow take the two vertices in the bucket and make them exactly the same objects. How would/should I go about this in particular? On a side note, is there a better option than spatial hashing for Unity and this particular situation?
Here's some code outlining my general pipeline for this algorithm as of now:
// Loop over all the vertices in a mesh
foreach (Vector3 vertex in meshVertices)
{
// If there is a matching vertex somewhere within a given
// threshold in the table, returns true.
if (SpatialHash.DoesTableContainSimilar(vertex, 0.001f))
{
// Retrive similar hash here, and then change the vertex
// location to match that of the other
}
}
As of now, the problem remains of how to actually take that other hash and turn it back into a Vector3, and then moving both of the vertices to the same location. As it stands, the actual Vector3 object is stored in the key, value pair in the hash table. Hypothetically, could I just take that other Vector3 and Lerp them until they meet a certain point (i.e. interpolate them), and then set both values to the new, interpolated values?
Are you looking at combining verticies or just placing them at the same position? I'm a bit confised?
It's just moving them to the same position. I originally was going to combine them, however, I ran into problems with vertex color. If I think of a new idea for that I'll put it in a different question to keep things on topic anyway.
shouldn't you hash table save the index of the vertice it hashes? (I think I know how hash tables work :P)
If so, can't you make the similar function return a vector2 of each index, then you can use it to get the vertices and set their position (I'm guessing you know how to do that) :)
Hmm... if I'm not mistaken my hash table stores the Vector3 and the hash in a key,value type pair. $$anonymous$$aybe I don't know either :P
I'll play around with it when I have time later.
It's a table right? Can't you add more columns? BTW is SpatialHash your own class? If so can you post it? It might help solve the issue :)
Answer by Fattie · Mar 27, 2013 at 10:49 AM
is it that you just want basic help in manipulating mesh in Unity ?
if so simply go here ...
http://answers.unity3d.com/questions/352162/optimized-vertex-manipulation.html
also here
http://answers.unity3d.com/questions/417483/is-there-a-way-to-assign-meshverticesi-directly.html
and so on.
http://answers.unity3d.com/questions/352513/ways-of-modificating-mesh-triangles.html
There are many -- priceless -- articles about mesh on this site. Just search.
If you have a specific question about hashes or the like, I guess that is a separate issue? I suggest just making a simple test project where you "move vertices" ... all teh code is given on the unity doco page...
http://docs.unity3d.com/Documentation/ScriptReference/Mesh.html
Thanks! The second link helped a lot. I didn't think to search that, as it never came across before.
Answer by BergOnTheJob · Jul 10, 2020 at 04:54 PM
If anyone is looking, this tool allows you to move, rotate, and scale a mesh's vertices, edges, and faces.
https://assetstore.unity.com/packages/slug/166155
it also has a bunch of other tools for modeling in Unity if you need to further edit the mesh.