I have a problem with creating algorithm for my index buffer.
for (int i = 0; i < indexvector3.Vertices.Count; i++)
{
for (int j = i + 1; j < indexvector3.Vertices.Count; j++)
{
if (Equals(indexvector3.Vertices, indexvector3.Vertices[j]) &&
(!Equals(tempMesh.Textures[indexvector3.Texcoords], tempMesh.Textures[indexvector3.Texcoords[j]])
|| !Equals(tempMesh.Normals[indexvector3.Normals], tempMesh.Normals[indexvector3.Normals[j]]))
)
{
constructedMesh.Vertices.Add(tempMesh.Vertices[indexvector3.Vertices[j]]);
constructedMesh.Normals.Add(tempMesh.Normals[indexvector3.Normals[j]]);
constructedMesh.Textures.Add(tempMesh.Textures[indexvector3.Texcoords[j]]);
indexvector3.Vertices[j] = constructedMesh.Vertices.Count - 1;
for (int k = j + 1; k < indexvector3.Vertices.Count; k++)
{
if(Equals(indexvector3.Vertices[j], indexvector3.Vertices[k]) && Equals(tempMesh.Textures[indexvector3.Texcoords[j]], tempMesh.Textures[indexvector3.Texcoords[k]])
&& Equals(tempMesh.Normals[indexvector3.Normals[j]], tempMesh.Normals[indexvector3.Normals[k]]))
{
indexvector3.Vertices[k] = constructedMesh.Vertices.Count - 1;
}
}
}
}
}
IndexVector3 - it is a class where all indices of vertices, texcoord and normals stored
tempMesh - class where stored not builded mesh with sorted coordinates
ans constructed mesh - class the same type as tempMesh, where I write coordinates in correct order.
After all I load it in my engine, but all models are broken. You can see it on screenshot.
I cannot found bug in my algorithm. Could someone help me with this problem, please?