   Vertex Declaration issue
  I have a model that has a set of meshes, each with a different number of texture coordinates per vertex.i.e. model B contains mesh C and D. C has 3 texture coordinates per vertex while D has 5.I tried to set something up like this (dynamically create the declaration elements) because I don't know how many texture coordinates a mesh is going to have until run time:class Vertex{   public: D3DXVECTOR3 Position; D3DXVECTOR2 *TexCoord;};..._NumberDeclarationElements = 1 + _NumberMultiTextures + 1;declaration = new D3DVERTEXELEMENT9[ _NumberDeclarationElements ];declaration[0].Stream = 0;declaration[0].Offset = 0;declaration[0].Type = D3DDECLTYPE_FLOAT3;declaration[0].Method = D3DDECLMETHOD_DEFAULT;declaration[0].Usage = D3DDECLUSAGE_POSITION;declaration[0].UsageIndex = 0;for( unsigned index = 1, k = 0; index < _NumberDeclarationElements-1; index++, k++ ){declaration[index].Stream = 0;declaration[index].Offset = 12 + k*8;declaration[index].Type = D3DDECLTYPE_FLOAT2;declaration[index].Method = D3DDECLMETHOD_DEFAULT;declaration[index].Usage = D3DDECLUSAGE_TEXCOORD;declaration[index].UsageIndex = k;}declaration[ _NumberDeclarationElements - 1 ].Stream = 0xFF;declaration[ _NumberDeclarationElements - 1 ].Offset = 0;declaration[ _NumberDeclarationElements - 1 ].Type = D3DDECLTYPE_UNUSED;declaration[ _NumberDeclarationElements - 1 ].Method = 0;declaration[ _NumberDeclarationElements - 1 ].Usage = 0;declaration[ _NumberDeclarationElements - 1 ].UsageIndex = 0;but that doesn't work too well (weird texturing issues).But if I create the vertex declarations and vertex classes like: (the "standard" way)D3DVERTEXELEMENT9 decl_1[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},  {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},D3DDECL_END() };D3DVERTEXELEMENT9 decl_2[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},  {0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},  {0, 20, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1},D3DDECL_END() };... etcclass Vertex1{   public: D3DXVECTOR3 Position; D3DXVECTOR2 TexCoord1;};class Vertex2{   public: D3DXVECTOR3 Position; D3DXVECTOR2 TexCoord1; D3DXVECTOR2 TexCoord2;};the results are betterIs there a way where I can create a vertex declaration like my first method or am I stuck with making several declarations?[Edited by - 16bit_port on May 12, 2010 7:52:44 PM]
  You can create the vertex declaration procedurally, but I don't think this:class Vertex{   public: D3DXVECTOR3 Position; D3DXVECTOR2 *TexCoord;};Will work. Direct3D expects vertex data to be contiguous in memory, but the above would result in a position vector followed by a pointer (which will mean nothing when interpreted as vertex data) pointing to the 'real' data, which Direct3D knows nothing about.You could use multiple vertex types as in your second example, or you could use multiple streams (e.g. one for position, normal, texcoord0, etc., and one additional stream for each extra texture coordinate).(There may be other solutions as well that I'm not thinking of - if so, I'm sure someone else will mention them.)   