Thanks for viewing... I'm rather stumped on a problem...
I have exported a model via 3dsmax to.X format and loaded this model into my D3D application.. What I am intending to do is access each triangle individually. The code is as follows:
Load the mesh:
ID3DXMesh* pMesh = NULL;
HRESULT hr=D3DXLoadMeshFromX(fileName, D3DXMESH_SYSTEMMEM, g_App.GetDevice(), NULL,&Model->materialBuffer,NULL, &Model->numMaterials,&pMesh);
Store the vertex data into a vector:
BYTE* pVerts;
pMesh->LockVertexBuffer(D3DLOCK_READONLY,(void**)&pVerts);
for (WORD i=0;i<pMesh->GetNumVertices();i++)
{
D3DXVECTOR3 vec3Vertice = *((D3DXVECTOR3*)(pVerts + i*D3DXGetFVFVertexSize(pMesh->GetFVF())));
PointList.push_back(vec3Vertice);
}
pMesh->UnlockVertexBuffer();
Store the index data into a vector:
unsigned short* pIndices = NULL;
pMesh->LockIndexBuffer( D3DLOCK_READONLY, (void**)&pIndices );
for(int x=0;x<pMesh->GetNumFaces();x++)
{
IndicesList.push_back(pIndices[x]);
}
pMesh->UnlockIndexBuffer();
And finally, store the triangles into a vector:
STriangle s;
for(int x=0;x<PointList.size();x+=3)
{
s.p0 = PointList[IndicesList[x]];
s.p1 = PointList[IndicesList[x+1]];
s.p2 = PointList[IndicesList[x+2]];
TriList.push_back(s);
}
Now, as you can see from my attached image, I am displaying the vertex count and indices count in the top left corner and I've double checked these values with what is in the .X file... So I am indeed getting the correct values for each as far as I know.. Now the problem is, when I render the triangles I'm missing quite a few.. I've tried multiple models, exporting with and without normals, reversing the draw order, ect. but I still seem to be missing tri's... Your help would be greatly appreciated.. I'm beating myself up over here trying to figure it out :-/.. Thanks in advance...
The draw functions if you are interested...
//Render triangle fuction
void RenderTri(STriangle* tri)
{
g_App.renderLine(CPos(tri->p0.x,tri->p0.y,tri->p0.z),CPos(tri->p1.x,tri->p1.y,tri->p1.z) ,D3DXCOLOR(255,0,0,255));
g_App.renderLine(CPos(tri->p1.x,tri->p1.y,tri->p1.z),CPos(tri->p2.x,tri->p2.y,tri->p2.z) ,D3DXCOLOR(255,0,0,255));
g_App.renderLine(CPos(tri->p2.x,tri->p2.y,tri->p2.z),CPos(tri->p0.x,tri->p0.y,tri->p0.z) ,D3DXCOLOR(255,0,0,255));
}
//Render the triangles each frame
for(int x=0;x<TriList.size();x++)
{
RenderTri(&TriList[x] );
}