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?
Nein heer du smign. ah open up the nine im heer du shmine