void RemoveDuplicateVertices(Mesh mesh) { MeshDates M = new MeshDates(); M.lV.AddRange(mesh.vertices); M.lUV.AddRange(mesh.uv); M.lB.AddRange(mesh.boneWeights); M.lT.AddRange(triangles); #region umaOutraTentativa //bool repita; //do //{ // repita = VerifiqueIgualdade(M); //} while (repita); #endregion //SubMeshDescriptor smd = mesh.GetSubMesh(3); //int max = smd.indexStart + smd.indexCount; for (int i = 0; i < M.lV.Count; i++) { for (int j = i + 1; j < M.lV.Count; j++) { if (M.lV[i] == M.lV[j]) { foreach (var V in weldVertices) { if (Vector3.SqrMagnitude(V - M.lV[i]) <= deltaVertex) { //if (weldVertices.Contains(M.lV[i])) //if (!EstaoNaMesmaSub(mesh, i, j)) SubstituaNosTriangulos(i, j, M); M.lUV[j] = M.lUV[i]; } } } } } Debug.Log("numero de vertices: " + M.lV.Count + " numero de ossos: " + M.lB.Count); mesh.vertices = M.lV.ToArray(); mesh.boneWeights = M.lB.ToArray(); for (int i = 0; i < M.lT.Count; i++) { mesh.SetTriangles(M.lT[i].ToArray(), i); } }
void ReplaceTrianglesID(MeshDates M, int i, int j) { for (int I = 0; I < M.lT.Count; I++) { for (int J = 0; J < M.lT[I].Count; J++) { if (M.lT[I][J] == j) { M.lT[I][J] = i; } } } }
//bool EstaoNaMesmaSub(Mesh m,int i, int j) //{ // for (int I = 0; I < m.subMeshCount; I++) // { // SubMeshDescriptor smd = m.GetSubMesh(I); // int end = smd.indexStart + smd.indexCount; // if ( // smd.indexStart <= i // && i < end // && smd.indexStart <= j // && j < end) // { // Debug.Log("Os indices: " + i + " e " + j + " estão na sub: " + I); // return true; // } // } // return false; //} #endregion void SubstituaNosTriangulos(int i, int j, MeshDates M) { for (int I = 0; I < M.lT.Count; I++) { for (int J = 0; J < M.lT[I].Count; J++) { if (M.lT[I][J] == j) { M.lT[I][J] = i; } } } }
bool VerifiqueIgualdade(MeshDates M) { for (int i = 0; i < M.lV.Count; i++) { for (int j = 0; j < M.lV.Count; j++) { if (i != j) { if (M.lV[i] == M.lV[j]) { M.lV.RemoveAt(j); M.lB.RemoveAt(j); ReplaceTrianglesID(M, i, j); return(true); } } } } return(false); }