So, I have a simple cube exported from Blender. D3DXLoadMeshFromX loads the mesh! However, if I try to use the ID3DXFile interfaces, it all comes tumbling down..
Here is my results with particular functions so far:
D3DXFileCreate(): S_OK. Works. No problems here.
ID3DXFile::RegisterTemplates(): D3DXFERR_PARSEERROR. This doesn't work period. Copying from the example in the SDK doesn't work either. My file doesn't contain the template headers, so do I even need to use this What am I doing wrong See code further down.
CreateEnumObjects(): S_OK. This actually works! So I at least have something right... I think...
ID3DXFileEnumObject::GetChildren(): S_OK. Works, except it always returns 0.
ID3DXFileEnumObject::GetChild(0, e): D3DXFERR_NOMOREOBJECTS. Well, I expected that after getting 0 with the last call.
Here is my code.. it's not spectacular, nor is it really any different from all the examples I've seen, except that it doesn't work.
Any help would be appreciated... my ability to load .x files has gone out the window with DirectX 9. I am using the August 2005 SDK too.
bool
TMeshX::ParseXFile(char *file_name){
char templates[] = "xof 0302txt 0032\template Vector\
{\
<3D82AB5E-62DA-11cf-AB39-0020AF71E433>\
float x;\
float y;\
float z;\
}\
template Mesh\
{\
<3D82AB44-62DA-11CF-AB39-0020AF71E433>\
DWORD nVertices;\
array Vector vertices[nVertices];\
DWORD nFaces;\
array MeshFace faces[nFaces];\
[...]\
}\
template MeshFace\
{\
<3D82AB5F-62DA-11cf-AB39-0020AF71E433>\
DWORD nFaceVertexIndices;\
array DWORD faceVertexIndices[nFaceVertexIndices];\
}\
template MeshNormals\
{\
<F6F23F43-7686-11cf-8F52-0040333594A3>\
DWORD nNormals;\
array Vector normals[nNormals];\
DWORD nFaceNormals;\
array MeshFace faceNormals[nFaceNormals];\
}\
template Material\
{\
<3D82AB4D-62DA-11CF-AB39-0020AF71E433>\
ColorRGBA faceColor;\
FLOAT power;\
ColorRGB specularColor;\
ColorRGB emissiveColor;\
[...]\
}\
template MeshMaterialList\
{\
<F6F23F42-7686-11CF-8F52-0040333594A3>\
DWORD nMaterials;\
DWORD nFaceIndexes;\
array DWORD faceIndexes[nFaceIndexes];\
[Material <3D82AB4D-62DA-11CF-AB39-0020AF71E433>]\
}\
template TextureFilename\
{\
<A42790E1-7810-11cf-8F52-0040333594A3>\
string filename;\
}\
template Frame\
{\
<3D82AB46-62DA-11CF-AB39-0020AF71E433>\
[...]\
}\
template ColorRGBA\
{\
<35FF44E0-6C7C-11cf-8F52-0040333594A3>\
float red;\
float green;\
float blue;\
float alpha;\
}\
template MeshTextureCoords\
{\
<F6F23F40-7686-11cf-8F52-0040333594A3>\
DWORD nTextureCoords;\
array Coords2d textureCoords[nTextureCoords];\
}"
;
ID3DXFile* f = NULL;
ID3DXFileEnumObject* e = NULL;
ID3DXFileData* d = NULL;
HRESULT hr =
0;SIZE_T count = NULL;
hr = D3DXFileCreate(&f);
DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// S_OKhr = f->RegisterTemplates((LPVOID)templates,
sizeof(templates) - 1);DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// D3DXFERR_PARSERRORhr = f->CreateEnumObject((LPVOID)file_name, D3DXF_FILELOAD_FROMFILE, &e);
DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// S_OKGUID g_mesh = {
0x3D82AB44, 0x62DA, 0x11CF, { 0xAB, 0x39, 0x00, 0x20, 0xAF, 0x71, 0xE4, 0x33 } };hr = e->GetDataObjectById(g_mesh, &d);
DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// D3DXFERR_NOTFOUNDhr = e->GetDataObjectByName(
"Mesh", &d);DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// D3DXFERR_NOTFOUNDhr = e->GetChildren(&count);
DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// S_OK: count == 0hr = e->GetChild(
0, &d);DXTrace(__FILE__, __LINE__, hr, NULL, TRUE);
// D3DXFERR_NOMOREOBJECTS
.x file frustration
tejasjunior
I actually came to the same conclusion after I played round with the template declaration for a whole day and got it working. The whole x file documentation is a little light on I think, but I'm slowly working it out now.
Kanna
There are a number of issues with your template declaration. First of all, any time you're running into issues with D3DX, I recommend that you link with d3dx9d. That way you'll get some extra debug information that may help point out any issues.
If you try to parse your templates, you'll notice the following error in the debug log:
D3DX: 1: syntax error near "nFaces"
D3DX: Parse error.
Now, admittedly this is not the most helpful of error messages, but at least you know where to look. The problem is in the line:
array MeshFace faces[nFaces];
If you look closely, at this point in the file MeshFace has not been defined, so when the parser ran into that symbol, it didn't know what to do with it, and declared a general parse error.
In other words, you'll need to reorder your templates so that they appear in order of use. There are a couple of other minor issues with your templates, for example you declared ColorRGBA but used ColorRGB, and you used Coords2d without definition.
Hope that helps, let me know if you're still running into issues.