# Multiple Indices Problem

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)?

• The pos argument is unused. – Pharap Apr 25 '17 at 7:04

You are assuming that the number of normals and number of positions is the same. This may not be true.

If there are more positions than normals, then you are accessing newnorms out of bounds.

Before fixing this you need to make a choice. Do you:

1. Want to draw non-indexed.
2. Want to draw indexed.

In case of 1, you simply generate non-indexed data by looking up the norm/pos before feeding it to OpenGL.

In case of 2, you would need to first determine all unique pos+norm values, before you can assign an index to it.

The first option is easier, and would mean using glDrawArrays, not glDrawElements. Some people argue that indexed primitives can be faster, but personally, I have found it not worth the extra effort.

Here's an answer that works for me, although doesn't directly answer the question.