- Home /
contains two different ids for the same vertex
There are two triangles that contain a a vertex of id 157 but then another triangle that uses that same vertex has it set at 224. Both has the exact same position
I opened up the mesh in my modelling program just to make sure it wasn't just two vertices overlapping each other but that wasn't the case. Any idea what could be going wrong?
I've got this little script that sets ball4 to the position of the vertex in the mesh and prints its vertex id. I move the ball to about the same position in the editor, click the button to run the function and it positions itself on the vertex it's closest to and returns its id. Thing is, I only ever get the id 157. When I uncomment "closestVertIndex = 224;" it sets itself to the exact same position as vertex 157.
int closestVertIndex = 0;
float checkVertDis = 0.0f;
float vertDistance = 10.0f;
// Iterate through piece's vertices and find closest vertice
for(int k = 0; k < meshOver.sharedMesh.vertexCount; k++)
{
// Check vertex distance. If there is a higher one, set verDistance to it
checkVertDis = Vector3.Distance(ball4.transform.position, meshOver.sharedMesh.vertices[k]);
// If we find a lower distance, set vertdistance to it
if(checkVertDis < vertDistance)
{
vertDistance = checkVertDis;
closestVertIndex = k;
}
}
// closestVertIndex = 224;
ball4.transform.position = meshOver.sharedMesh.vertices[closestVertIndex];
print(closestVertIndex);
First check that the vertices are in fact at the same location and not just very close
$$anonymous$$esh mesh=meshOver.shared$$anonymous$$esh;
Vector3 vert1=mesh.vertices[157];
Vector3 vert2=mesh.vertices[224];
Debug.Log(vert1+" "+vert2+" "+(vert1==vert2));
If they are the same vertex then see if both have the same normal
Vector3 normal1=mesh.normals[157];
Vector3 normal2=mesh.normals[224];
Debug.Log(normal1+" "+normal2+" "+(normal1==normal2));
If they have the same position and normal then there is no reason to have both. Find the vertices in the modeling program using their IDs (showing mesh element id's depends on the program, in blender you would need to start in debug mode).
Your answer
Follow this Question
Related Questions
Why does the default Unity sphere have duplicate vertices? 1 Answer
Earth mesh rendering 1 Answer
Huge GC Overhead When Accessing Tris/Verts From Mesh? 2 Answers
Accessing Mesh: Triangle and Vertex array fields directly? 0 Answers
Extruding faces of a mold. Need to properly assign vertices to triangles 0 Answers