Search code examples
c++directx-9

ID3DXBaseMesh::CloneMeshFVF returns D3DERR_INVALIDCALL


I am attempting to take a mesh loaded from a .x file in directx 9 and clone it into another FVF format to get out the vertices that i want.

LPD3DXMESH pMesh;
DWORD numMaterials;
LPD3DXBUFFER pMaterialBuffer;
HRESULT hr = D3DXLoadMeshFromX( file, D3DXMESH_SYSTEMMEM, pDevice, NULL, &pMaterialBuffer, NULL, &numMaterials, &pMesh ); // Loads just fine, I can even render it

LPD3DXMESH clone;
pMesh ->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_XYZ, pDevice, &clone); // Trying to get only the xyz data out

At the clone stage i get a D3DERR_INVALIDCALL error. However, I dont see anything wrong with any of my arguments.

What I am trying to achieve from this is to eventually get all the vertex data out of the buffer i want non-dependant on the type of .x file i am loading.

typedef struct VERTEX_TYPE 
{
    float position[3];
} VERTEX;

void* pTemp;
VERTEX* pVertexData;

DWORD nNumVerts = mesh->GetNumVertices();
DWORD nSizeVerts = mesh->GetNumBytesPerVertex();
DWORD nNumFaces = mesh->GetNumFaces();


pVertexData = new VERTEX[nNumFaces * 3];
mesh->LockVertexBuffer(D3DLOCK_READONLY, &pTemp);
memcpy(pVertexData, pTemp, sizeof(VERTEX)*nNumVerts);
mesh->UnlockVertexBuffer();

Any assistance as to where i am going wrong?


Solution

  • I figured it out. The problem was that i was creating an directX9 EX device. I am not sure as to why it requires a regular device compared to an EX one but that fixed my error and it all works fine.