#### Archived

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

# Vertex Data from .X Files, Some confusion

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

## 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;

//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 on other sites
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 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 on other sites
You must read form the index buffer wich vertices are being used to form a face.

You must lock it first...

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 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.

Pat

##### 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.

1. 1
Rutin
64
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633413
• Total Posts
3011759
• ### Who's Online (See full list)

There are no registered users currently online

×