   A mesh of problems
  I'm having a lot of trouble getting the function D3DXComputeTangentFrame working.  I've been at this most of the day, any help is appreciated.I'm using the FVF: D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX3 | D3DFVF_TEXCOORDSIZE2(0) | D3DFVF_TEXCOORDSIZE3(1) | D3DFVF_TEXCOORDSIZE3(2)1) I D3DXLoadMeshFromX into mesh1.2) Then I CloneMeshFVF into mesh2 with the above FVF.3) Then I GenerateAdjacency so I can D3DXCleanMesh with the D3DXCLEAN_BOWTIES flag.  The "cleaned" mesh is stored back in mesh1.4) Finally, I try to call D3DXComputeTangentFrame and it fails with D3DERR_INVALIDCALL.  I have also tried using the Ex version of the function.  Even when I specify an output mesh (and take out the generate_in_place flag), the call still fails.It should be noted that I release each mesh after transfering to the other.  I haven't used meshes a lot, so I hope I'm not making any noob mistakes.If I had to guess, my FVF is wrong.Also, I'm using the Dec. '04 SDK with debug output all the way up, and I'm not getting any information (just a bunch of redundant texture states with my shaders).Thanks for any help.   
  Seems to me that you are trying to generate the tangent and binormal information for a given mesh.To save yourself alot of pain, you should be using vertex declarations.This is a simple vertex declaration that you might useD3DVERTEXELEMENT9 elements[] ={{ 0, sizeof( float ) * 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },{ 0, sizeof( float ) * 3, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },{ 0, sizeof( float ) * 6, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },{ 0, sizeof( float ) * 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },{ 0, sizeof( float ) * 15, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },D3DDECL_END()};You will then clone your mesh given the above mentioned vertex declarationLPD3DXMESH temp;pMesh->CloneMesh( D3DXMESH_MANAGED, elements, pDevice, &temp )Mesh->Release();pMesh = temp;D3DXComputeTangentFrame(pMesh, 0);This should work fine.I hope this helps.Take care.   ;  I changed the declaration a little.pos:3norm:3tex:2binormal:3tangent:3For a total of 54 bytes.The function returns success, but the model shows up in all black.  I'm guessing either the normals are getting destroyed, but when I call D3DXComputeTangentFrame I don't specify the calculate_normals flag.How much does the spacing matter in the declaration?  I noticed your sample declares a float3 for texture coords and then gives it 24 bytes for the data.Does the ComputeTangentFrame function assume the data will be in any special order, or does it read the vertex format and calculate accordingly?Thanks for the help.   ;  If you don't have it generate the normals, then it cannot generate the binormals or tangents either.  You could have the normals generated before the tangents by using D3DXComputeNormals.   ;Quote:Original post by DXnutIf you don't have it generate the normals, then it cannot generate the binormals or tangents either.  You could have the normals generated before the tangents by using D3DXComputeNormals.You misunderstood me.  I already have the normals.  I believe they are getting destroyed by the function.   ;Quote:Original post by blaze02How much does the spacing matter in the declaration?  I noticed your sample declares a float3 for texture coords and then gives it 24 bytes for the data.Does the ComputeTangentFrame function assume the data will be in any special order, or does it read the vertex format and calculate accordingly?AFAIK, all of the mesh functions should honour your vertex declaration completely. Gaps, such as in Pieters example are a little unusual, but shouldn't cause any problems (unless there's a bug in that version of D3DX). What will of course cause problems is if the offsets in your declaration cause overlaps between elements.Could you post your modified vertex declaration? From the components you've mentioned above, I'd expect it to look like:D3DVERTEXELEMENT9 elements[] ={{ 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_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },D3DDECL_END()};And the sizeof each vertex in your vertex stream to be 56 bytes.It may be worth locking the processed mesh and giving the vertices a visual inspection in the debugger too.   ;Quote:Original post by S1CAQuote:Original post by blaze02How much does the spacing matter in the declaration?  I noticed your sample declares a float3 for texture coords and then gives it 24 bytes for the data.Does the ComputeTangentFrame function assume the data will be in any special order, or does it read the vertex format and calculate accordingly?AFAIK, all of the mesh functions should honour your vertex declaration completely. Gaps, such as in Pieters example are a little unusual, but shouldn't cause any problems (unless there's a bug in that version of D3DX). What will of course cause problems is if the offsets in your declaration cause overlaps between elements.Could you post your modified vertex declaration? From the components you've mentioned above, I'd expect it to look like:D3DVERTEXELEMENT9 elements[] ={{ 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_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },D3DDECL_END()};And the sizeof each vertex in your vertex stream to be 56 bytes.It may be worth locking the processed mesh and giving the vertices a visual inspection in the debugger too.My declaration is exactly what you posted, except I swapped the position of usage_binormal and usage_tangent flags.   