Jump to content
  • Advertisement
Sign in to follow this  
Mistro

Getting vertex and other data from .x file or LPD3DXMESH

This topic is 4829 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

Well I was wondering if there was any way to get a .x file and get an array of vertices, indices, texture coords, and normals from it without creating a custom parser. If a custom parser is needed, how would I go about creating one for just the data which i need stated above. I do not need any excess information, just vertices, indices, texture coords, and normals. It would be even better if there was a way to get this data from the LPD3DXMESH object itself once it has been loaded wtih the data. Is there a funciton in it to get this data? Somethign along the lines of LPD3DXMESH->GetVertexBuffer(LPDIRECT3DVERTEXBUFFER9) LPDIRECT3DVERTEXBUFFER9->GetPrivateData(...) But what would I have to give the GetPrivateData function to get what I'm looking for? What I mean is, how would the information returned in the void pointer be organized so to speak? EDIT: ok so the format for get prvate data would be HRESULT GetPrivateData( REFGUID refguid, void *pData, DWORD *pSizeOfData ); Now what exactly do I give it? I mean I can easily just give it a void pointer but then how do I get the vertex coords, tex coords and normals out of it? Same deal with the index buffer... [Edited by - Mistro on August 25, 2005 2:09:05 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well mabye this might clear things up a bit. After fooling around with it a bit and a thorough look into the MSDN, I whipped this thing up:


typedef struct VERTEX_TYPE
{
float x, y, z;
float vcN[3];
float tu, tv;
} VERTEX;










void LoadFromModel(char* cFileName, UINT* nID)
{
LPD3DXMESH Mesh;

void* pTemp;

VERTEX* pVertexData;

Log("Loading Mesh: %s", cFileName);
if (FAILED(D3DXLoadMeshFromX(
cFileName,
D3DXMESH_IB_SYSTEMMEM,
m_pDevice,
NULL,
NULL,
NULL,
NULL,
&Mesh)))
{
Log("Couldn't load mesh");
}

Log("Success");

Mesh->LockVertexBuffer(0, &pTemp);

DWORD nNumVerts = Mesh->GetNumVertices();
Log("Verts Found: %u", nNumVerts);

DWORD nSizeVerts = Mesh->GetNumBytesPerVertex();
Log("Size of Verts: %u", nSizeVerts);

if (nSizeVerts == sizeof(VERTEX))
Log("Size of vertex matches custom Vertex");
if (Mesh->GetFVF() == FVF_VERTEX)
Log("Vertex is in matching format");


memcpy(pVertexData, pTemp, sizeof(VERTEX)*nNumVerts);

Mesh->UnlockVertexBuffer();
}










However, I get a run time error at the Unlock Buffer part. However, when I simple add this bit:


//...the other stuff...

memcpy(pVertexData, pTemp, sizeof(VERTEX)*nNumVerts);

for (int i = 0; i<nNumVerts; i++)
Log(" Vertex[%i]: %f,%f,%f", i, pVertexData.x,pVertexData.y,pVertexData.z);

Mesh->UnlockVertexBuffer();

//...the other stuff...




It works. However I see no reason why it should work now as to before.
The log function is basically just taking the file built into the game class, doing a sprintf on the input and writing it to that file. I see no reason why that should have any effect on whether theres an error unlocking the buffer.

Hope this clears it up a bit and mabye gives some of you ideas...


Just a note: there are many log calls since I want to know whats happeneing ;)

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!