Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

Reading an X File

This topic is 4363 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, i need some help on how to load an X File with a new interface LPD3DXFILE (not the IDirect3DXFile). I was just reading this book called Worldware Publishing DirectX9 Graphics - The Definite Guide To Direct3D, and it shows how to load an X File but its examples are so bad that when i use them i always get access violation errors or something. What im trying to do is to load a skinned mesh from an xfile, but first i have to read it. Also i need help on how to check a file data if its a mesh or not, how can i compare two guids? What i do is 1. I create the xfile interface - D3DXFileCreate(&ixfile); 2. I create the enum object- CreateEnumObject(filename, D3DXF_FILELOAD_FROMFILE,&ienumobj); 3. I get the children - GetChildren(&children); 4. I cycle through them with "for(SIZE_T i = 0; i < children; i++)" and use GetChild(i, &filedata) on every child. 5. I check whether the file is of MESH type, and if not I pass the file data to the other function which goes deeper into the hierchy and checks that filedata for further children it might have. This is all the code for it //////////////////////////////////////////////////////////// void ReadXFile(LPCSTR filename) { // creating the file interface if(FAILED(D3DXFileCreate(&ixfile))) MessageBox(NULL, "Failed", "no x interface", MB_OK); if(ixfile == NULL) MessageBox(NULL, "Failed", "xfile null", MB_OK); // Createing the ennum obj which will retrieve children if(FAILED(hresult = ixfile->CreateEnumObject(filename, D3DXF_FILELOAD_FROMFILE, &ienumobj))) { MB_FAILED("ceo failed"); if(hresult == D3DXFERR_BADVALUE) MessageBox(NULL, "Failed", "Bad VAl", MB_OK); if(hresult == D3DXFERR_PARSEERROR) MessageBox(NULL, "Failed", "Pare eerr", MB_OK); if(ienumobj == NULL) MessageBox(NULL, "Failed", "ienum null", MB_OK); } if(ienumobj == NULL) MessageBox(NULL, "Failed", "ienum null", MB_OK); // Gets all the Children of the x file SIZE_T children = 0; if(ienumobj->GetChildren(&children) == D3DXFERR_BADVALUE) MB_FAILED("bad value"); LPD3DXFILEDATA filedata; // iterating through each child and doing something to it for(SIZE_T i = 0; i < children; i++) { ienumobj->GetChild(i, &filedata); // do stuff here//////// ObjectInfo(OBJ_TYPE, NULL, filedata, g_guid); if(g_guid == MESH_GUID) { //NewMesh.LoadMultipleMeshesFromX(_d3d9device, filedata); MB_FAILED("Mesh Found"); } else { MB_FAILED("Mesh not found"); ManageChild(&filedata); } //////////////////////// filedata->Release(); } ienumobj->Release(); } void ManageChild(LPD3DXFILEDATA * filedata) { MB_FAILED("ent"); SIZE_T children = 0; filedata->GetChildren(&children); LPD3DXFILEDATA childdata = NULL; if(children == 0) { MB_FAILED("children 0"); return; } if(children == 0) MB_FAILED("manc() failed to return"); for(SIZE_T i = 0; i < children; i++) { hresult = filedata->GetChild(i, &childdata); // Do stuff here ObjectInfo(OBJ_TYPE, NULL, childdata, g_guid2); if(g_guid2 == TID_D3DRMMesh) { MB_FAILED("Child Mesh found"); //NewMesh.LoadMultipleMeshesFromX(_d3d9device, childdata); } else MB_FAILED("Child Mesh Not Found"); ////////////////// childdata->Release(); } }

Share this post


Link to post
Share on other sites
Advertisement
1) Use source tags.
2) Access violations usually mean you are reading or writing to memory you don't own; check your array accesses, allocations, and bounds.
3) What's wrong with D3DXLoadMeshFromX()?

Share this post


Link to post
Share on other sites
I cant use D3DXLoadMeshFromX() since im trying to load a skinned mesh, which means that i have to load the geometry and the skin-info seperatly. So i have to scan through an X File looking only for mesh templates. And by the way what are source tags?

Share this post


Link to post
Share on other sites
"It would seem that you didn't register the templates"

Do I always have to register templates? For instance in this eample im trying to tiny.x (a skinned mesh provided with DirectX SDK). What if the templates are already registered? And how do i know which templates are in the X File if I didn't make it (it was generated by a plugin) because the file is pretty big, and it would be troubleseome to go manually go through the file lloking for templates. TThnx

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!