PDA

View Full Version : Index list problem



Henri
04-07-2003, 11:29 PM
I have a problem that I don’t seem to get my head around. I’m loading in an md2 model, and I end up with a vertex index list and a texture coordinate index list. (They are currently stored like this:
texIndex[numFaces][3] and
verIndex[numFaces][3])
Now I would like to draw the models using vertex arrays, and thus I can only use one index list. And that has to be the vertex list. Right?! And I have this up and running and the model look good. But the textures are obvious a mess! So how do I sort the texture coordinates so they match with the vertices. I have tried different ways but it doesn’t come out right…

So how do I sort the texture coordinates and by what?

// Thanks Henri

Bob
04-08-2003, 12:55 AM
Go through each index in verIndex and compare with texIndex. Keep going as long as they are the same. As soon as they are no longer the same, find the index in texIndex that matches the one in verIndex, and swap it into the right place in texIndex.



for i = each index in the vertex array
if(verIndex[i] = texIndex) continue

j = find(position in texIndex which has the same value as verIndex[i] in the range [i, end])
swap(texIndex[i], texIndex[j])
end for

That assumes that the two arrays are of the same size and that there are no duplicate copies in one array that are not present in the other array. For example, a cube can share vertex position but maybe not texture coordinate in the corners. It's easy to detect this; find (in the algo above) does not find the corresponding index.

Henri
04-08-2003, 03:26 AM
I checked and found that I have more texture coordinates than I have vertex coordinates... And that's probably why my first attempt to solve the problem did not work. I also found that the number of texture and vertex coordinates vary in most of the file format that I intend to load [obvious it does not have to be equal according to the specifications of the file formats] so I decided to create two new arrays that holds every point, like a “glDrawArrays()” array should be like...

If anyone has any idea or input on how to solve this in another way it’s welcomed... It’s somewhat bulky to store it this way. But at least it works now.