Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Boris Karloff

Loading X-files

This topic is 5384 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''m trying to get some understanding of the mysterious X file format. The DX8.1 SDK help isn''t much help, as it basically sums up stuff and only very generally say how to do something. Anyway, I clued together bits and pieces and I made this very simple x file called "test.x" by hand:
xof 0302txt 0032

Mesh {
5;
0.0;1.0;0.0;,   
-1.0;0.0;-1.0;, 
-1.0;0.0;1.0;,  
1.0;0.0;-1.0;,  
1.0;0.0;1.0;;   
6;		
3;1;3;2;, 	
3;3;4;2;, 	
3;1;0;3;, 	
3;3;0;4;, 	
3;4;0;2;, 	
3;2;0;1;; 	
}
It''s just a simple mesh of a triangle without any materials, normals or texture coordinates. It loads perfectly in the Mesh Viewer application that came with the SDK, so the file itself is correct. Now, using the guidelines given in the SDK help file ("Loading an X File", to be exact), I''m trying to read it using the following code:
LPDIRECTXFILE pDXFile = 0;
LPDIRECTXFILEENUMOBJECT pDXFileEnumObj = 0;
LPDIRECTXFILEDATA pDXFileData = 0;
const GUID* pGuid;

DWORD bufSize=0;
void* pData = 0;
DWORD data;
HRESULT hr;

hr = DirectXFileCreate(&pDXFile);

if (SUCCEEDED(hr))
{
	if (SUCCEEDED(pDXFile->CreateEnumObject("test.x", DXFILELOAD_FROMFILE, &pDXFileEnumObj)))
	{
		if (SUCCEEDED(pDXFileEnumObj->GetNextDataObject(&pDXFileData)))
		{
			if (SUCCEEDED(pDXFileData->GetType(&pGuid)))
			{
			}

			if (SUCCEEDED(pDXFileData->GetData("minor", &bufSize, &pData)))
			{
				DWORD* pd = (DWORD*)pData;
				data = *pd;
			}

			pDXFileData->Release();
		}



		if (SUCCEEDED(pDXFileEnumObj->GetNextDataObject(&pDXFileData)))
		{
			if (SUCCEEDED(pDXFileData->GetType(&pGuid)))
			{
			}

			if (SUCCEEDED(pDXFileData->GetData("nVertices", &bufSize, &pData)))
			{
				DWORD* pd = (DWORD*)pData;
				data = *pd;
			}

			pDXFileData->Release();
		}

	}
}

pDXFile->Release();
pDXFileEnumObj->Release();
When I step through this with the debugger, it runs up to the first GetNextDataObject, which fails. The debug output gives me the following information: --- D3DXOF:Unknown object type Mesh. D3DXOF:xparse::yylex_ascii: parser: failed to create data object D3DXOF:17: syntax error near "1" D3DXOF:XStreamRead::GetNextObject: Error while parsing stream D3DXOF:GetNextObject: Parse error. --- Apparently, it claims Mesh is an unknown object type, which seems very strange to me as Mesh is listed as a template in the help SDK. Besides, Mesh Viewer loaded it just fine, and I know MilkShape 3D exports working X files that use the Mesh type but don''t have a Mesh template definition in them. So.. What''s going on? Can you, or can''t you use the templates listed in the SDK? And when do you use RegisterTemplates? When defining your own templates?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
just to make sure, if you''re not doing this for research or just out of interest, do you know you''re reinventing the wheel? there''s already D3DX utility functions to do what you want done. and there''s also the common framework classes for the SDK samples that do what you want done.

but anyway, yeah you need to call RegisterTemplates, even with the standard templates, after the IDirectXFile interface object has been created. there''s a header called rmxftmpl.h that contains the char array for those templates, pre-defined. i think this header gets included via the high-level includes. you would use it like so:

pDXFile->RegisterTemplates((VOID*)D3DRM_XTEMPLATES,
D3DRM_XTEMPLATE_BYTES));

if you have your own templates, i''m not sure if you have to build an array that contains both yours plus the standard ones, or if you can just call RegisterTemplates multiple times.

Share this post


Link to post
Share on other sites
I''m doing this primarily out of interest. I wanted to see what was going on in x-files, and how they work exactly.

I know of the various D3DXLoadMeshFromX functions and the like, but they all return LPD3DXMESH structures... Which are good, but again.. it all rather hides away how everything works, and I''d like to know.

Anyway, interesting thing about the included array with default template definitions... Why don''t they note these sort of things in the SDK help file? How are people supposed to figure this out? How did you figure it out, anyway?

It works perfectly, by the way. Thanks a lot! Weird that the help states "-If- templates are present". Of course they are present... It''d only be a header and some comments otherwise, wouldn''t it?

Hmm. Well, thanks again for the help!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Boris Karloff
Anyway, interesting thing about the included array with default template definitions... Why don''t they note these sort of things in the SDK help file? How are people supposed to figure this out? How did you figure it out, anyway?

i had a project in which i wanted to use the .x files that came with the Matrox Parhelia (sp?) demo, but they wouldn''t load with the D3DX utility functions due to some assumptions made regarding texture use. so i started poking around the SDK''s common framework .x file code until it made sense and i could write my own loader.
quote:
It works perfectly, by the way. Thanks a lot! Weird that the help states "-If- templates are present". Of course they are present... It''d only be a header and some comments otherwise, wouldn''t it?

Hmm. Well, thanks again for the help!

i think what the docs are referring to is if the .x file has template definitions, not template use. a complete .x file would include a template definition for each template used, so you could conceivably load that file into memory and then use RegisterTemplates to parse that array as opposed to using the header file''s array.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
i think what the docs are referring to is if the .x file has template definitions, not template use.


Yeah, I thought of that, too... Still, the fact that it lists RegisterTemplates as an optional step is a bit strange... It's not optional. You have to do it, either on the included definitions or on your own file, or it won't work.
Oh well. The docs still seem very flaky on the whole subject of X files. The DX9 docs are an improvement somewhat, as far as I have seen... Maybe it's time to move on to DX9.

Anyway, thanks again!

[edited by - Boris Karloff on September 23, 2003 3:30:09 AM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!