Original Post
Hello, My bounding sphere function used to work okay. Unfortunately, my cMesh class has got a bit more sophisticated and caused a knock on effect. I've added code that computes the tangents of a supplied mesh. It clones the previous mesh into a new one with the extended FVF. Unfortunately, now the GetFVF() function I'm using returns this error: D3DX: ID3DXMesh::GetFVF: The declaration cannot be converted to an FVF SDK says: and heres the call to GetFVF(): Thanks for yuor advice. Simon
Quote:Sounds like my problem... how do convert this declaration into an FVF compatible one? Heres the code which builds the tangents.
This method can return 0 if the vertex format cannot be mapped directly to an FVF code. This will occur for a mesh created from a vertex declaration that doesn't have the same order and elements supported by the FVF codes.
// Expand the mesh to hold tangent data
D3DVERTEXELEMENT9 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_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
D3DDECL_END()
};
hr = m_pMesh->CloneMesh( dw32BitFlag | D3DXMESH_MANAGED, decl, g_device,
&l_pTempMesh );
if (FAILED(hr))
{
StringCchPrintf( temp, 100, "cSimpleMesh::CloneMesh() - FAILED - '%s'\n", m_name );
OutputDebugString( temp );
SAFE_RELEASE(l_pTempMesh);
return;
}
hr = D3DXComputeTangent( l_pTempMesh, // input mesh
0, // TexStageIndex
0, // TangentIndex
0, // BinormIndex
0, // Wrap
pAdjacency//NULL // Adjacency
);
m_pMesh->Release();
m_pMesh = l_pTempMesh;
delete pAdjacency;
// END OF TANGENT BUILDER ----------------------------------------------------------------------
D3DXVECTOR3 *vertices;
if( SUCCEEDED( mesh->LockVertexBuffer( D3DLOCK_READONLY, (void**)&vertices ) ) )
{
D3DXComputeBoundingSphere( vertices, mesh->GetNumVertices(), D3DXGetFVFVertexSize( mesh->GetFVF() ), &m_sphere->centre, &m_sphere->radius );
mesh->UnlockVertexBuffer();
}