Jump to content
  • Advertisement
Sign in to follow this  

Problem with the vertex values in .X file

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

Hi, I'm trying to process the vertices of a mesh in .X File. The problem that i'm facing is that after loading the mesh using D3DXLoadMeshFromX() function and retriving the vertex buffer of the mesh, i found the vertex values in the buffer and in the .X file are not same. Here is the code
[source lang = "cpp"]
class CVertex
	D3DXVECTOR3 Position; 
	D3DXVECTOR3 Normal;  
	float u, v;           

HRESULT LoadMesh()

// Variable Declaration goes here....
CVertex *pVertices;
CVertex *pDVertices;

hr =  D3DXLoadMeshFromX ("teapot.x",
if (FAILED (hr))
	return hr;

// Create a new vertex buffer
pd3dDevice->CreateVertexBuffer (MeshVertexCount*sizeof (CVertex),

TeapotMesh->GetVertexBuffer (&SMeshBuffer);

// Lock the vertex and the index buffer
SMeshBuffer->Lock(0, 0, (void**)&pVertices, 0);
DMeshBuffer->Lock (0, 0, (void**)&pDVertices, 0);

// Copy the vertices from the mesh
memcpy (pDVertices, pVertices, MeshVertexCount * sizeof (CVertex));

// Unlock the vertex and the index buffer

return hr;

i'm using vc++6. In the debug mode i've checked the values of pVertices and i found that it is not the same as in the .X file. If i render the mesh using the values of pDVertices, the mesh is being rendered correctly. But the values in X file and the vertex buffer are different. (The same problem appears even if i clone the mesh) What might be wrong? Could any one help me

Share this post

Link to post
Share on other sites
How are you checking the contents of the mesh?

Are you using PIX to check the contents of the mesh? If not, PIX will show you the values in the vertex and index buffers.


Share this post

Link to post
Share on other sites
"not the same" isn't a very useful description - help us to help you.

If your mesh is rendering as expected then the data is probably correct just that you're misinterpretting/misusing it.

The obvious thing that jumps out to me is that you're not referring to the index buffer. D3DX will use indexed geometry and therefore the ordering of vertices in the VB may not be the same as they are in the original file - reading the first three vertices from the VB are not necessarily the first triangle in the mesh.

If I'm wrong then further qualifying your "not the same" description would be useful. How are they different? How are you checking? What other processes are you using? Where are you exporting data from, using what tools? At which point are you checking the file - via a text editor or via a 3D modeller? etc..etc..


Share this post

Link to post
Share on other sites
Thanks for ur reply

"not the same" - i mean the value in the pVertices array (which corresponds to Vertex, normal and texcoord values) is not the same as the values in the .X file's Vertex, Normal and texcoord values. Hope now u will be clear

I'm NOT refering to the index Buffer. i've tried something like the following

[source lang = "cpp"]
CVertex *Vertex1, *Vertex2, *Vertex3;

Vertex1 = new CVertex [MeshFaceCount];
Vertex2 = new CVertex [MeshFaceCount];
Vertex3 = new CVertex [MeshFaceCount];

MeshVertexCount = TeapotMesh->GetNumVertices();
MeshFaceCount = TeapotMesh->GetNumFaces();

// Get the mesh vertex and the index buffer
// Lock the vertex and the index buffer

// Copy the vertex values from the mesh
for (DWORD Face=0; Face<MeshFaceCount; Face++)
// Copy the vertices
Vertex1->Position[Face] = pVertices->Position[pIndices[3*Face+0]];
Vertex2->Position[Face] = pVertices->Position[pIndices[3*Face+1]];
Vertex3->Position[Face] = pVertices->Position[pIndices[3*Face+2]];

// Unlock the vertex and the index buffer

But that also gives me the wrong result. For example i'm giving the values found in the .X File and in the pVertices array

.X File
first three values 28.647617;0.000000;49.110203;, (i've properly mapped the values in index buffer to vertex buffer)

first value in pVertices array
pVertices[0] : 1.14615, 1.960, 0.00512281 (Vertex values)

I'm checking the values of the vertices after loading the mesh from the x file
I'm checking the values for the vertices in the pVertices array in vc++ by placing check points after getting the vertex buffer of the mesh during runtime.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
You can't assume your vertex/index buffers are in a certain format when accessing them directly!
ust check FVF flags...

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.

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!