   access to the vertex data
  Hi.I use DirectX 9.My problem is: how can I access to the data (position, normal, ...) of each vertex ?The 3D object mesh is loaded from the DirectX file (*.x), with the function "D3DXLoadMeshFromX": D3DXLoadMeshFromX(MESH_FILE,0,D3DDev,NULL,NULL,NULL,NULL,&D3DMesh)How can I access to the data of each vertex from the this ?Someone know the solution ?Thanls for all.   
  You have to lock the vertex buffer, which provides you with a pointer to the raw vertex data.  With ID3DXMesh, you can just call LockVertexBuffer rather than calling Lock directly on the vertex buffer.   ;Quote:Original post by MJPLockVertexBufferSo, I have to use "LockVertexBuffer" for locking and access to the vertex data. Then I can manipolate the position of the vertex and then unlock. Is this the correct procedure ?;  Yes, that is correct.   ;Quote:Original post by MJPYes, that is correct.One question:if I use the follow:D3DMesh->LockVertexBuffer(D3DLOCK_DISCARD, ppData)"ppData" just contain the vertex data (position, normal, ... ) ?   ;Quote:Original post by ClaudioQuote:Original post by MJPYes, that is correct.One question:if I use the follow:*** Source Snippet Removed ***"ppData" just contain the vertex data (position, normal, ... ) ?No - because D3DLOCK_DISCARD means "Throw away the contents of the buffer and give me a new one" (more or less).You want to lock with either 0 or D3DLOCK_READONLY.   ;Quote:Original post by Evil SteveQuote:Original post by ClaudioOne question:if I use the follow:*** Source Snippet Removed ***"ppData" just contain the vertex data (position, normal, ... ) ?No - because D3DLOCK_DISCARD means "Throw away the contents of the buffer and give me a new one" (more or less).You want to lock with either 0 or D3DLOCK_READONLY.So, if I use "0" or "D3DLOCK_READONLY":  D3DMesh->LockVertexBuffer(0, ppData) the vertex data (position, ...) are in "ppData" ? But if I want to modifiy te position of the vertex,the flag has to be "0" and not "D3DLOCK_READONLY" ?   ;  Yes, it will be a pointer to a buffer of data that has the layout specified in your vertex declaration.  So if your VB has a position, texture coordinate, and normal, then each vertex will have a total 8 float's.If you create a struct whose layout exactly matches your vertex layout, you can just treat the buffer pointer as a pointer to an array of this struct type.  So for instance with the layout I just mentioned, you would have this:struct VertexPositionTextureNormal{    D3DXVECTOR3 Position;D3DXVECTOR2 TexCoord;    D3DXVECTOR3 Normal;}Then when you lock...VertexPostionTextureNormal* verts = NULL;D3DMesh->LockVertexBuffer(D3DLOCK_DISCARD, (VOID**)&verts);DWORD  numVerts = D3DMesh->GetNumVertices();for (int i = 0; i < numVerts; i++){   // Access verts as an array to access the vertex data};  While if I want to use the vertex buffer "D3DVB" ? struct VERTEX3D{D3DXVECTOR3 position;   D3DXVECTOR3 normal;DWORD color;};VERTEX3D * vertex = NULL;D3DVB->Lock(0, 0, (VOID**) &vertex, D3DLOCK_READONLY); // lockDWORD numVerts = D3DMesh()->GetNumVertices(); // total number of verticesfor(int i=0; i < numVerts; i + +){   // access to: vertex.position, vertex.normal, vertex.color}D3DVB->Unlock(); // unlock Is correct ?Appear error about "access violation to..."Thanks for all.   ;Quote:Original post by ClaudioWhile if I want to use the vertex buffer "D3DVB" ?*** Source Snippet Removed ***Is correct ?Yes.Quote:Original post by ClaudioAppear error about "access violation to..."Because you're not checking return values. What do the Debug Runtimes say?   