.x file frustration
So, I have a simple cube exported from Blender.D3DXLoadMeshFromX loads the mesh! However, if I try to use theID3DXFile 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
{
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_OK
hr = 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
