1

Like in this question, I've loaded some vertex and index data from a format (COLLADA) where the indices are interleaved. The answer suggested to use buffer textures but also warned about losses in rendering performance, which I want to avoid.
So the problem is to merge all the interleaved index and vertex data into multiple VBOsand a single index buffer.
The data is given like this

P N P N P N P N P N P N ...
0 0 1 0 2 0 7 1 6 1 5 1 ...

Where each Prefers to a position and each Nto a normal vector.

One way to solve this problem would be to keep track of all the tuples (of two in this case) in a list. If I read the next tuple, I search for this tuple in the list and if it exists then I use this position as the new index data and if it doesn't I construct a new vertex and put the tuple on the list.
Of course this is hideously slow, as it includes comparing those tuples to each existing one.

Is there are more efficient way to accomplish this?

Community
  • 1
  • 1
haansn08
  • 155
  • 2
  • 10
  • As @derhass also suggests in the answer below, use a more efficient data structure than a list. I posted some pseudo-code in an answer here: http://stackoverflow.com/questions/23349080/opengl-index-buffers-difficulties/23356738#23356738. – Reto Koradi Aug 09 '14 at 17:22

2 Answers2

1

So the really slow part of that is the searching in the list - so don't do that. The use of a hash table will speed up things greatly in that scenario - I've actually implemented somehting like that, and it did work really well - as long as you can afford the extra memory for the hash table.

derhass
  • 38,787
  • 2
  • 42
  • 61
0

I wrote a tool called meshtool that can do what you want.

The filter for doing what you want is called normalize_indices:

  --normalize_indices   Goes through all triangle sets, changing all index
                        values to go from 1 to N, replacing sources to be size
                        N

However, it generally works best with a few other filters too. I would suggest trying something like:

meshtool --load_collada yourfile.dae --medium_optimizations \
    --normalize_indices --save_collada yourfile-optimized.dae

You can install it with:

pip install meshtool
jterrace
  • 57,555
  • 21
  • 140
  • 184