Recently, I've been trying to use COLLADA
files in OpenGL. The problem that a lot of people before me have run into is COLLADA
's indice structure. It has multiple sets of indices, the first is for position, the second for the normal.
I know by now that it is completely impossible for OpenGL to use multiple sets of indices, so I must rearrange my normals so that I can use my position indices for my normals.
I've already made some code for this, but it doesn't seem to turn out right.
private static Vector3[] RearrangeNormals(Vector3[] norms, Vector3[] pos, int[] posindices, int[] normindices)
{
Vector3[] newnorms = new Vector3[norms.Length] ;
for (var i = 0; i < norms.Length; i++)
{
newnorms[posindices[i]] = norms[normindices[i]];
}
return newnorms;
}
With this function, it seems like half of my Suzanne mesh has it's normals correct, the other half... not so much. Here's an image of what I'm getting with my lighting test.
How should I handle rearranging my normals (or texcoords maybe in the future)?
pos
argument is unused. \$\endgroup\$