• Advertisement
Sign in to follow this  

Vertex/Index reading

This topic is 4558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone. I am trying to read data back from my mesh's. I can retrieve the index information and vertex information into variables by using mesh->LockVertexBuffer() and mesh->LockIndexBuffer(), but the problem is in how to read this. At the moment I am saving the index data as a WORD array and the Vertex data as a DWORD array. I've also tried FLOAT for the vertex. Those were the two that seemed might be indicated by examining the .x files. My problem is that the values that I print to the screen do not seem to match those in the file. It is possible this may be a problem with how I am printing to screen though, rather than the data itself. So my question is two-fold: 1) What format do these two values need to be saved as, and 2) How do I convert it to a string so that I can output it correctly to the screen? Thanks everyone for the help. I can post code if that will help. PS. I'm using C/C++

Share this post


Link to post
Share on other sites
Advertisement
Indices are usually WORDs, but they can also be DWORDs, it depends if it's 16bit (WORD) indices, or 32bit (DWORD).
You can see if your ID3DXMesh uses 32 bit indices like this:

bool bUses32bitIndices = mesh->GetOptions() & D3DXMESH_32BIT;


Now the vertices use different structs that matches it's FVF.
To get the FVF that your mesh uses, you'd call mesh->GetFVF().

If you don't know the original FVF, you can call mesh->CloneMeshFVF() to create a mesh with the desired FVF.

here's an example:

DWORD newFVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE;
D3DXMESH *pNewMesh;
DWORD meshOptions = mesh->GetOptions();
hr = mesh->CloneMeshFVF( meshOptions, newFVF, d3dDevice, &pNewMesh );
... // handle errors
mesh->Release();
mesh = pNewMesh;

struct myVertices
{
D3DXVECTOR3 position;
D3DXVECTOR3 normal;
D3DCOLOR color;
};

myVertices* pVerticesData;
mesh->LockVertexBuffer( D3DLOCK_READONLY, &pVerticesData );
... // handle errors;
... // access your vertex data with pVerticesData[vertexIndex].xxxx
mesh->UnlockVertexBuffer();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement