Skip to main content
gamedev.net
🔒 Locked

.X File Question

Started by madmonkey28 Mar 3, 2009 at 8:09 PM 0 replies 500+ views
Original Post
madmonkey28
madmonkey28
I have a problem loading a couple of .x file. The number of materials returned by D3DXLoadMeshFromX is not the same as the number of attributes after optimizing the mesh. This makes it impossible to map textures to attributes. I initially thought it was a problem with the file itself but DirectX Viewer and my format conversion tools manage to display the textures correctly. What could DX Viewer be doing differently / what am I doing wrong? Relavent portion of mesh loading code:

ID3DXMesh* pMesh = 0;
ID3DXBuffer* adjBuffer  = 0;
ID3DXBuffer* mtrlBuffer = 0;
ID3DXBuffer* effectInstances = 0;
DWORD numMtrls = 0;
DWORD attrSize = 0;
//Load From File
D3DXLoadMeshFromX(FileName.c_str(), D3DXMESH_MANAGED, D3D9NullRaster, &adjBuffer, &mtrlBuffer, &effectInstances, &numMtrls, &pMesh)
//Sort by attribute
pMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT, (DWORD*)(adjBuffer->GetBufferPointer()), 0, 0, 0)
//Get number of attributes
pMesh->GetAttributeTable(0, &attrSize);
//attrSize != numMtrls???

This works just fine for several other .x files.
madmonkey28
madmonkey28
I managed to fix this by ignoring all materials with RGB value = 0.75294125. The textures then aligned correctly with the attributes. I'm not really sure where the magic number came from.
This is definitely a hack though but I guess it should be fine until I get around to writing my own mesh format.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.