The source data indexes multiple streams/pools of vmaps (position, uv) for each individual vertex element. Your mesh may also store discontinuous uv-map data meaning a vertex may have different uv-values associated with it for different triangles connected to the vertex. You can only set a single index buffer, so you'll have to combine position- and uv-data into a single indexable stream.
So, you need to unweld/duplicate vertices. The most intuitive way is to construct both the vertex- and the index stream in a single pass:
- Set up an "unweld-buffer" of vertex-count number of elements, each element in this buffer stores a linked-list of possible position-uv-normal etc. sets for a specific vertex combined with an index into the vertex buffer.
- Loop over all vertices in all triangles. (foreach(mesh->triangles as triangle) foreach(triangle->vertices as vertex))
- Grab for each vertex the set of position, uv, etc. data (relative to the current triangle for discontinuous maps)
- Look for a compatible existing element in the unweld-buffer, if it exists place the existing index associated with this element into the index buffer, if it does not, create a new element, assign it the index "vertex-buffer count + 1" and add it to both the linked list and the vertex buffer.
Edited by eppo, 03 November 2013 - 08:10 AM.