I have the following vertex declration:
struct MESHVERTInstanced
{
float x, y, z; // Position
float nx, ny, nz; // Normal
float tu, tv; // Texcoord
float idx; // index of the vertex!
float tanx, tany, tanz; // The tangent
const static D3DVERTEXELEMENT9 Decl[6];
static IDirect3DVertexDeclaration9* meshvertinstdecl;
};
And I declare it as such:
const D3DVERTEXELEMENT9 MESHVERTInstanced::Decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, 32, D3DDECLTYPE_FLOAT1, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
D3DDECL_END()
};
What I try to do next is copy an ID3DXMesh into another one with the new vertex declaration as such:
model->CloneMesh( model->GetOptions(), MESHVERTInstanced::Decl,
gd3dDevice, &pTempMesh );
When I try to get the FVF size of pTempMesh (D3DXGetFVFVertexSize(pTempMesh->GetFVF())) I get '0' though the size should be 48.
The whole thing is fine if I don't have the last declaration, '{ 0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },' in it and the CloneMesh function does not return a FAIL. I've also tried using different declarations such as D3DDECLUSAGE_TEXCOORD and that has worked fine, returning a size of 48. Is there something specific about D3DDECLUSAGE_TANGENT I don't know?
I'm at a complete loss as to why this isn't working...