Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi basicaly i am loding .X file via following mehod

C#
(D3DXLoadMeshFromX(filename.c_str(), D3DXMESH_SYSTEMMEM, gd3dDevice,
        &adjBuffer, &mtrlBuffer, 0, &numMtrls, &meshSys);


now i want to store mtrlBuffer,meshSys,adjBuffer,numMtrls into binary file.
so i have created structure

struct Xfile
{	Xfile():X_mesh(NULL), X_adjBuffer(NULL), X_mtrlBuffer(NULL), X_numMtrls(0){}
	ID3DXMesh* X_mesh ;
	DWORD* X_adjBuffer  ;
	DWORD* X_mtrlBuffer ;
	DWORD X_numMtrls    ;
	
};


then my data saving code is

C#
Xfile xmem;
xmem.X_mesh= meshSys;
xmem.X_adjBuffer = (DWORD*)adjBuffer->GetBufferPointer();
xmem.X_mtrlBuffer = (DWORD*)mtrlBuffer->GetBufferPointer();
xmem.X_numMtrls=numMtrls;

   FILE * pFile = fopen("C://CustomX.bin",  "wb");
    fwrite(&xmem, 1, sizeof(xmem), pFile);
    fclose(pFile);
<pre></pre>


my material and adjuncy buffer is saving properly but mesh data is not stored into the .bin file
Posted

1 solution

fwrite(&xmem, 1, sizeof(xmem), pFile);

Assuming you are on 32-bit windows, you write:
4 bytes containing the address of meshSys
4 bytes containing the address returned by adjBuffer->GetBufferPointer()
4 bytes containing the address returned by mtrlBuffer->GetBufferPointer()
4 bytes containing the DWORD X_numMtrls

On 64-bit Windows each of the addresses will be 8 bytes.

sizeof(xmem) evaluates to the size of the Xfile struct in bytes.


Usually I would use D3DXSaveMeshToX[^] to accomplish this task.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
TRUSHAL RANE 2-Jun-12 4:49am    
i had tried like this
DWORD* X_mesh

xmem.X_mesh= new DWORD(sizeof(meshSys));
ZeroMemory(xmem.X_mesh,sizeof(xmem.X_mesh));
memcpy(xmem.X_mesh,temp,sizeof(meshSys));


and i am reading the saved file
FILE * sFile = fopen("C://CustomX.bin", "rb");
if(sFile != NULL)
{
fread(&xmem, 1, sizeof(xmem), sFile);
}

memcpy(meshSys,xmem.X_mesh,sizeof(meshSys));

but meshSys is not properly initialized & i am getting access violation while using meshSys
Espen Harlinn 2-Jun-12 5:06am    
fread & and fwrite just reads and writes bytes. If you are going to implment custom reading and writing you need a notion about how this works. A good place to start would be reading up on the X file format: http://msdn.microsoft.com/en-us/library/windows/desktop/bb172359(v=vs.85).aspx

You can load an X file using D3DXLoadMeshFromX http://msdn.microsoft.com/en-us/library/windows/desktop/bb172890(v=vs.85).aspx

Defining your own custom format and implmenting custom read/write functionality is a lot of work.

memcpy(meshSys,xmem.X_mesh,sizeof(meshSys));
copies 4 bytes from the location starting at xmem.X_mesh (it's a pointer) into the memory starting at the address meshSys (this too is a pointer).
TRUSHAL RANE 2-Jun-12 4:50am    
actualy i am loading X file & i want to extract the data & stored into custom format...
Sandeep Mewara 14-Jun-12 16:31pm    
My 5!
Espen Harlinn 14-Jun-12 16:32pm    
Thank you, Sandeep :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900