When I clone an ID3DXMesh with blend weights the blend weights end up breaking (but not completely, mostly the arms and fingers are skewed in strange directions), my code is very simple:
LPD3DXMESH pTempMesh;
if( model /*model is a mesh with animations, bone hierarchy, etc))
{
if ( FAILED ( model->CloneMesh( model->GetOptions(), pDecl/*a vertex declaration with blend weights*/,
gd3dDevice, &pTempMesh ) ) )
{
ReleaseCOM( pTempMesh );
return E_FAIL;
}
}
model = pTempMesh;
return S_OK;
The skewed vertex issue does not happen if the vertex declration has no blend weights so I'm guessing that's somehow the culprit but not sure why exactly, especially since it looks like it's working for most of the mesh just not some parts of the mesh...
It's also worth noting this only happens to models which are comprised of different objects (i.e. in 3D Studio Max if the entire mesh is a single model and is exported it works fine, if the mesh is more than one model, like say a person and a hat existing as two seperate objects in max the issue happens to either the person or hat).
*EDIT: Ok, I fixed it. I'm an idiot. The old vertex declration is as follows:
{
{ 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, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
{ 0, 44, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
{ 0, 52, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
D3DDECL_END()
};
However that's incorrect, I need 3 blend weights, not 2. So changing D3DDECLUSAGE_BLENDWEIGHT to FLOAT3 fixed the problem. It was rather daft on my part because when I checked the original vertex declration I was changing I saw blendweights was float3, for some reason in the new one I decided to make it float2. Don't know why, but changing it back to float3 fixed it.