Advertisement Jump to content
Sign in to follow this  
Revision

D3D Mesh Issues (indices + vertices != correct triangle count)

This topic is 1888 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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] );
}

 

 

 

 

Share this post


Link to post
Share on other sites
Advertisement

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);
}


It should be:
STriangle s;
for(int x=0;x<IndicesList.size();x+=3)
{
        s.p0 = PointList[IndicesList[x]];
	s.p1 = PointList[IndicesList[x+1]];
	s.p2 = PointList[IndicesList[x+2]];
	TriList.push_back(s);
}


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites

L. Spiro,

 

Thank you for your prompt response...I'm not sure why I went about that backwards.. Thank you for that correction, this did in fact render quite a few more of my triangles but I am still missing some! Any thoughts on the source of the problem? Thank you for your time!

Share this post


Link to post
Share on other sites
.X files use triangle strips, not lists.
 
STriangle s;
for(int x=2;x<IndicesList.size();++x)
{
        s.p0 = PointList[IndicesList[x-2]];
	s.p1 = PointList[IndicesList[x-1]];
	s.p2 = PointList[IndicesList[x]];
	TriList.push_back(s);
}


L. Spiro Edited by L. Spiro

Share this post


Link to post
Share on other sites
STriangle s;
for(int x=2;x<IndicesList.size();++x)
{
        s.p0 = PointList[IndicesList[x-2]];
	s.p1 = PointList[IndicesList[x-1]];
	s.p2 = PointList[IndicesList[x]];
	TriList.push_back(s);
}

L. Spiro,

 

This produced the same result as your previous correction to this routine.. Although it was an improvement something still isn't right. What am I missing here? Am I going about this correctly? This is typical... I almost reach my goal and something is amiss....

Share this post


Link to post
Share on other sites

Well it should have pushed back more triangles then so I'm confused if you say you got the same result?

 

EDIT: I'd try debugging it with a simpler mesh than Mr. Teapot anyway, try a cube and look at the values you get in the debugger.

Edited by Paradigm Shifter

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!