So I'm using ID3DXMESH to store a .X file, I'm loading it into the application with D3DXLoadMeshHierarchyFromX. I'm trying to get the vertex and index buffer from the mesh but getting incorrect results. The vertex buffer is correct but the index buffer is not, at least I don't think so. To simplify things; I created a basic cube mesh .X file. I've been changing around the index values of the file and the model changes shape but the returned index buffer does not reflect what is stated in the file.
DWORD numFaces = pCurrentFrame->pMeshContainer->MeshData.pMesh->GetNumFaces();
if(MESHFLAGS&D3DXMESH_32BIT)
{
DWORD* indices;
DWORD tempIndex;
pCurrentFrame->pMeshContainer->MeshData.pMesh->LockIndexBuffer(D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, (void**)&indices);
for(DWORD k = 0; k < (numFaces*3); k++)
{
memcpy(&tempIndex, indices, sizeof(DWORD));
indices++;
}
}
else
{
WORD* indices;
WORD tempIndex;
pCurrentFrame->pMeshContainer->MeshData.pMesh->LockIndexBuffer(D3DLOCK_NOOVERWRITE | D3DLOCK_READONLY, (void**)&indices);
for(DWORD k = 0; k < (numFaces*3); k++)
{
memcpy(&tempIndex, indices, sizeof(WORD));
tempIndex = 0;
indices++;
}
}
pCurrentFrame->pMeshContainer->MeshData.pMesh->UnlockIndexBuffer();
what I get back for my index values is 0,1,2,3,4,5,6,7,8,9,10,6,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,23,28,29,30,31,28,32
here's the vertex and index information from the file.
Mesh { //Cube_001 Mesh
36;
-1.000000; 1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000; 1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000;-1.000000; 1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000; 1.000000;,
0.999999;-1.000001; 1.000000;,
1.000000;-1.000000;-1.000000;,
1.000000; 0.999999; 1.000000;,
1.000000; 1.000000;-1.000000;,
1.000000;-1.000000;-1.000000;,
0.999999;-1.000001; 1.000000;,
1.000000; 0.999999; 1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000; 1.000000; 1.000000;,
1.000000; 0.999999; 1.000000;,
0.999999;-1.000001; 1.000000;,
-1.000000;-1.000000; 1.000000;,
-1.000000; 1.000000; 1.000000;,
-1.000000;-1.000000;-1.000000;,
1.000000;-1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;,
-1.000000; 1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
1.000000; 1.000000;-1.000000;;
12;
3;0;1;2;,
3;1;4;5;,
3;6;7;9;,
3;9;10;11;,
3;3;1;4;,
3;15;16;12;,
3;18;14;20;,
3;21;22;23;,
3;24;25;27;,
3;27;35;29;,
3;30;31;32;,
3;33;34;35;;
It doesn't seem like it's right, is the LoadHierarchy function doing some kind of optimization behind the scenes, are the returned values somehow correct or am I just doing something wrong?
Thanks for any help!