Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

patindahat

Vertex Data from .X Files, Some confusion

This topic is 5214 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

I''ve been experiencing some strange problems with my code, and came to realize that when I load meshes (the ones that come with the DX9 SDK) from X files the number over vertices isn''t always a multiple of 3. I thought with D3D everything was done with triangles, and therefore the # of Vertices should be sets of three. Basically I''m trying to get the 3 points of each polygon for my collision detection, but I''m having problems because of the # of vertices, and the fact that I''m getting the same values for EVERY vertex.
//record the # of vertices

	m_NumVertices = m_pMesh->GetNumFaces();

	//Lock the vertex buffer

	PBYTE pVertices = NULL;
	m_pMesh->LockVertexBuffer(D3DLOCK_READONLY, (BYTE **)&pVertices);

	//copy the vertex data over

	m_pVertices = new D3DXVECTOR3[m_NumVertices];
	memcpy(m_pVertices, pVertices, sizeof(D3DXVECTOR3) * m_NumVertices);

	//Done with the vertex buffer so unlock it

	m_pMesh->UnlockVertexBuffer();
Hope I got those beginning and ending tages correct so that it shows the code nicely, its been a while. Thanks for any help guys. Pat

Share this post


Link to post
Share on other sites
Advertisement
Ok, so with a look at a cube I have 12 faces (as expected with 2 triangles per side). And 8 vertices.

Mabye I''m misunderstanding what a vertex is. I thought that an index would be what I was getting above. No repeats. But it looks like I''m incorrect. So if To get triples of points in 3D space to describe each polygon do I need to read the index buffer? And how do I know any many indices there are (no GetNumIndex method).

Share this post


Link to post
Share on other sites
The best thing to do is use D3DXLoadMeshFromX() to load the file. If you really want to load it by hand, use the X file interfaces.

Examine the mesh output from that function, regardless. It''ll show you how the index and vertex buffers are set up from the file. In short, yes, you need to examine the index buffer for faces. Indices will come in triples, each indexing into the vertex buffer.

I like pie.

Share this post


Link to post
Share on other sites
You must read form the index buffer wich vertices are being used to form a face.

You must lock it first...
m_pMesh->LockIndexBuffer(D3DLOCK_READONLY, (BYTE**)&pIndex);

Then you can start reading in groups of three, in a similar way as you do it for vertices, and then you''ll know which vertex to copy.

I think you get the idea... if you need some code just let me know.

James.

Share this post


Link to post
Share on other sites
Ahh I see, makes since. The vertices are just a list of each individual vertex, a squence (no repitions). The index buffer is the triples describing which vertex for each point. You guys have helped alot, thanks. One quick last one. I''m reading triplets from the index buffer, the # of triplets is the # of faces? This seems intuitive to me but I don''t wanna get hung up any more.

Thanks again guys for the quick and really helpfull answers.

Pat

Share this post


Link to post
Share on other sites
Yes, you''re right. Every face is made up by three index (dunno how to say it in plural). The meshes use TriangleList so it''s allways true in this case.

James.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!