• 12
• 12
• 9
• 10
• 13

# Problem with the vertex values in .X file

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

## 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
{
public:
D3DXVECTOR3 Position;
D3DXVECTOR3 Normal;
float u, v;
};

{

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

hr =  D3DXLoadMeshFromX ("teapot.x",
D3DXMESH_MANAGED,
pd3dDevice,
&MaterialBuffer,
NULL,
&NumMaterials,
&TeapotMesh);
if (FAILED (hr))
{
return hr;
}

// Create a new vertex buffer
pd3dDevice-&gt;CreateVertexBuffer (MeshVertexCount*sizeof (CVertex),
D3DUSAGE_WRITEONLY,
0,
D3DPOOL_MANAGED,
&DMeshBuffer,
NULL);

TeapotMesh-&gt;GetVertexBuffer (&SMeshBuffer);

// Lock the vertex and the index buffer
SMeshBuffer-&gt;Lock(0, 0, (void**)&pVertices, 0);
DMeshBuffer-&gt;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
DMeshBuffer-&gt;Unlock();
SMeshBuffer-&gt;Unlock();

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

Dave

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

hth
Jack

##### Share on other sites
Hi,
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 meshfor (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 on other sites
Could any one please tell me why this happens. please solve my problem

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