Hi guys
Can some one show me how to export group vertex from ID3DXMesh to text file ?
The following code provides you with vertices and face indices from a D3DXMesh. You will have to write the code that saves it to file yourself, but that should be easy.
LPD3DXMESH m_pD3DMesh;
void MeshXWrapper::GetMeshData(int *pMeshVertexCount, dVector3 **ppMeshVertices,
int *pMeshIndexCount, int **ppMeshIndices)
{
LPDIRECT3DVERTEXBUFFER9 pVB = NULL;
m_pD3DMesh->GetVertexBuffer(&pVB);
struct MY_FVF {
float x;
float y;
float z;
};
void *pbVertexData;
if (SUCCEEDED(pVB->Lock(0, 0, &pbVertexData, D3DLOCK_READONLY))) {
DWORD numBytesPerVertex = m_pD3DMesh->GetNumBytesPerVertex();
int numVertices = m_pD3DMesh->GetNumVertices();
*ppMeshVertices = new dVector3[numVertices];
unsigned char *pVBDataPos = (unsigned char*)pbVertexData;
for (int i=0; i < numVertices; i++) {
(*ppMeshVertices)[i][0] = ((MY_FVF*)pVBDataPos)->x;
(*ppMeshVertices)[i][1] = ((MY_FVF*)pVBDataPos)->y;
(*ppMeshVertices)[i][2] = ((MY_FVF*)pVBDataPos)->z;
(*ppMeshVertices)[i][3] = 0;
pVBDataPos += numBytesPerVertex;
}
pVB->Unlock();
*pMeshVertexCount = m_pD3DMesh->GetNumVertices();
}
// Index buffer
LPDIRECT3DINDEXBUFFER9 pIB;
m_pD3DMesh->GetIndexBuffer(&pIB);
D3DINDEXBUFFER_DESC indexDesc;
pIB->GetDesc(&indexDesc);
LPVOID pbIndexData;
if (SUCCEEDED(m_pD3DMesh->LockIndexBuffer(D3DLOCK_READONLY, &pbIndexData))) {
*pMeshIndexCount = indexDesc.Size / sizeof(unsigned short);
*ppMeshIndices = new int[*pMeshIndexCount];
for (int i=0; i<(*pMeshIndexCount)/3; i++) {
unsigned short i0 = ((unsigned short*)pbIndexData)[i*3+0];
unsigned short i1 = ((unsigned short*)pbIndexData)[i*3+1];
unsigned short i2 = ((unsigned short*)pbIndexData)[i*3+2];
(*ppMeshIndices)[i*3+0] = i0;
(*ppMeshIndices)[i*3+1] = i1;
(*ppMeshIndices)[i*3+2] = i2;
}
m_pD3DMesh->UnlockIndexBuffer();
}
pIB->Release();
pVB->Release();
}
thanks , i want to access to material group then save them to text files. i think your code just save total faces.
for exemple , there is a model with 3 group mesh inside it , evry mesh has his own material , i want to access to all groups and save the separatly to some files , so any group with his material in one file.