I have to triple the amount of vertices in my buffer??

Started by
0 comments, last by rubberkidney 21 years, 1 month ago
ok...here is a sample portion of the ASE file format...more specifically the vertex, face and texture data: (dont worry my problem is down at the bottom somewhere..i just wanted to give some info) *MESH_NUMVERTEX 8 *MESH_NUMFACES 12 *MESH_VERTEX_LIST { *MESH_VERTEX 0 -19.6749 -20.4781 -16.9385 *MESH_VERTEX 1 19.9857 -20.4781 -16.9385 *MESH_VERTEX 2 -19.6749 20.2262 -16.9385 *MESH_VERTEX 3 19.9857 20.2262 -16.9385 *MESH_VERTEX 4 -19.6749 -20.4781 16.4599 *MESH_VERTEX 5 19.9857 -20.4781 16.4599 *MESH_VERTEX 6 -19.6749 20.2262 16.4599 *MESH_VERTEX 7 19.9857 20.2262 16.4599 } *MESH_NUMTVERTEX 12 *MESH_TVERTLIST { *MESH_TVERT 0 0.0000 0.0000 0.0000 *MESH_TVERT 1 1.0000 0.0000 0.0000 *MESH_TVERT 2 0.0000 1.0000 0.0000 *MESH_TVERT 3 1.0000 1.0000 0.0000 *MESH_TVERT 4 0.0000 0.0000 0.0000 *MESH_TVERT 5 1.0000 0.0000 0.0000 *MESH_TVERT 6 0.0000 1.0000 0.0000 *MESH_TVERT 7 1.0000 1.0000 0.0000 *MESH_TVERT 8 0.0000 0.0000 0.0000 *MESH_TVERT 9 1.0000 0.0000 0.0000 *MESH_TVERT 10 0.0000 1.0000 0.0000 *MESH_TVERT 11 1.0000 1.0000 0.0000 } *MESH_NUMTVFACES 12 *MESH_TFACELIST { *MESH_TFACE 0 9 11 10 *MESH_TFACE 1 10 8 9 *MESH_TFACE 2 8 9 11 *MESH_TFACE 3 11 10 8 *MESH_TFACE 4 4 5 7 *MESH_TFACE 5 7 6 4 *MESH_TFACE 6 0 1 3 *MESH_TFACE 7 3 2 0 *MESH_TFACE 8 4 5 7 *MESH_TFACE 9 7 6 4 *MESH_TFACE 10 0 1 3 *MESH_TFACE 11 3 2 0 } Ok...the first chunk is the vertex coordinate data...the second part is the texture coordinate data, and the third part is the indices for the texture coordinates corresponding to the faces...i left out the index buffer part because it was ugly and not super relavent to my problem. Now then, as you can see there are more texture coordinates than there are vertices...this is the first thing that is confusing...after much debate i decided that the best course of action would be to just increase the number of vertices that i have, this would triple the amount and I would have tons of repeats...but at least my texture would display correctly. I wrote the code to parse the last two sections not thinking I would have to much of a problem when it dawned on me that adding more vertices would really screw up my index buffer...does anyone know how i could index these new vertices correctly? Or better yet a way that i could maintain the original number of vertices and still have the texture render correctly. I dont want to have to mess with changing the vertex buffer to much because that would slow things down a lot, so rendering faces one at a time is out....any ideas? suggestions? anything at all would be very helpful! thanks
Advertisement
It sounds like you should have two index lists in your ASE file: one giving the vertex position indices for each face vertex, and another giving the texture coordinate indices for each face vertex.

You don't need an index buffer, you only need a vertex buffer. Create (3 * numFaces) vertices, then copy the position and uv data into these:


  void SetVertices (    const unsigned int numFaces, // 12    const unsigned int* const* const posIndices, // [12][3]    const D3DXVECTOR3* const pos, // [8]    const unsigned int* const* const uvIndices, // [12][3]    const D3DXVECTOR2* const uv, // [12]    Vertex* const verts) // [36]{    for (unsigned int face = 0; face < numFaces; ++face)    {        for (unsigned int i = 0; i < 3; ++i)        {            Vertex& vert = verts[(3 * face) + i];            vert.pos = pos[posIndices[face][i]];            vert.uv = uv[uvIndices[face][i]];        }    }}  


It's unlikely that you can do much better than this for a cube. For larger and complex models, it's usually worth welding vertices and indexing into the resulting smaller set. You can do this yourself or use D3DXWeldVertices if you prefer.


[edited by - Osc on March 6, 2003 12:11:44 PM]

This topic is closed to new replies.

Advertisement