Sign in to follow this  

Problem with saving data to X file

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

I want to seperate Frame Hierarchy, Mesh + Skin Info and Animation from one file, and write it 3 different files. I wrote a code that saved hierarchy from tiny.x to tiny_bones.x file. Well, something was saved in this file so it looked ok. But the mesh viewer was not loading a mesh from tiny_bones.x. I know that one frame (which was saved) "Body" includes mesh info in tiny.x hierarchy, and this info was saved also. Because of the above problem I tried to do more simple thing. //I have got ID3DXFile object, templates registered, pEnumObject and pSaveObject created Now, when I want to do the most simple thing: ID3DXFileSaveData *pSaveData=NULL; pSaveObject->AddDataObject(TID_D3DRMFrame,"FRAME",0,0,0,&pSaveData); pSaveObject->Save(); The new created file remains empty. This is strange because before I wrote something to an X file, and now when I want something simple to write, nothing happens. Can anyone help?

Share this post


Link to post
Share on other sites
Well I tried to add Frame, then to this Frame I added Transform Matris. After this I saved the data to file. But it still remains empty! This is strange, like I said, I have a code which somehow works (saves data), but when I try to reduce this code to just save Root frame and its matrix it saves nothing!

Here is the code which (I think) should save Frame + Matrix (doesn't work):

ID3DXFile *pFile=NULL;
ID3DXFileSaveObject *pSaveObject=NULL;
ID3DXFileSaveData *pSaveData=NULL;
D3DXMATRIX *I; I=new D3DXMATRIX; D3DXMatrixIdentity(I);

D3DXFileCreate(&pFile);
pFile->RegisterTemplates((LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES);
pFile->CreateSaveObject((LPVOID)"frame.x",D3DXF_FILESAVE_TOFILE,D3DXF_FILEFORMAT_TEXT,&pSaveObject);
pSaveObject->AddDataObject(TID_D3DRMFrame,"Root",0,0,0,&pSaveData);
pSaveData->AddDataObject(TID_D3DRMFrameTransformMatrix,0,0,sizeof(D3DXMATRIX),(LPCVOID)&I,&pSaveData);
pSaveObject->Save();

Share this post


Link to post
Share on other sites
I am loosing my mind! I sit here for few hours and I haven't found the solution yet!

PLEASE, can someone write a working piece of code which saves a D3DXMATRIX to an .X file for me?. I would be really grateful!

----------------------------------------------
wrote by sad man from Poland who needs help :(

Share this post


Link to post
Share on other sites
I made some "experiments" with D3DXSaveMeshHierarchyToFile before. I am not sure if this function will manage to write only animation to one file, only hierarchy to another and only mesh + skin info to another.

But does this mean, that the couple (ID3DXFileSaveData and ID3DXFileSaveObject) is just a big joke from Microsoft? (Hihi, using it is prohibited, anyone who will dare to break this rule will be punished :) <- just kidding).

I still believe that this will work and that I made a stupid mistake somewhere... but where?

Share this post


Link to post
Share on other sites
The problem is that no one really knows what you can and cannot do with those interfaces, except for the MS programmer(s) that created them. Why on earth they would create such a complicated but flexible file format and do nothing to document it (beyond the reference stuff) is beyond me. I asked numerous questions about .x files and the DX animation interfaces on the MSDN forums, and no one could answer them. THe MS MVPs told me that is why no one uses them, and I should just write my own file format and animation classes.

You may have stumbled on a bug where you can't save anything unless there is a mesh object.

Share this post


Link to post
Share on other sites
I am very suprised now. I never thought that there may be some functions which simply "don't work" or rather no one knows how to use them...

So not using .x files is a common situation? I mean, if they are making such troubles, then most people decide to not use them, right?

One thing letf. There is a tutorial: http://www.toymaker.info/Games/html/x_file_saving.html
I used method: ctrl+c, ctrl+v on this tutorial, to create a frame + matrix. The result was the same, empty file. This is strange, because since this TUTORIAL is showing HOW TO SAVE to .x file, it should work, right?

Share this post


Link to post
Share on other sites
The X file saving functions do work, and it's pretty clear what you can and cannot do with them.

The first thing I would look at is the cast to LPVOID in CreateSaveObject() -- it's supposed to take a proper filename. If you're compiling with UNICODE, you need to pass a wstring, such as L"filename.x".

The second thing I would look at is the return code for all those function calls. Right now, there's no checking.

The third thing I would do is to include <atlbase.h> and use CComPtr<> instead of raw pointers to interfaces. Right now, you're not releasing the objects you're creating; there's some chance that the file won't save interfaces that still have outstanding refcounts (although that feels like stretching it a bit).

I've written exporters for two different tools (DeleD and 3dsMax) that write to .X files, so it's certainly quite possible. The most annoying part is when you put in mal-formatted data compared to the template; the only way the system will tell you about it is crashing inside Save().

Share this post


Link to post
Share on other sites
Well I am not using UNICODE, and I made a check for the return value. In each case it was S_OK. So I would like to ask you hplus0603, if you could please write a code which will save a D3DXFRAME fo .x file. That would be really helpful.

Share this post


Link to post
Share on other sites
I would like to thank all of you for help!

hplus0603 was right! Saving to .x works, and I only had to replace usuall pointers with CComPtr<> !

THANK YOU AGAIN! :-)

Share this post


Link to post
Share on other sites

This topic is 4163 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this