Jump to content
  • Advertisement
Sign in to follow this  
Claudio

access to the vertex data

This topic is 3414 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 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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
LockVertexBuffer


So, 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 ?

Share this post


Link to post
Share on other sites
Quote:
Original post by MJP
Yes, that is correct.


One question:
if I use the follow:

D3DMesh->LockVertexBuffer(D3DLOCK_DISCARD, ppData)


"ppData" just contain the vertex data (position, normal, ... ) ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Claudio
Quote:
Original post by MJP
Yes, 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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by Claudio

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.


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" ?

Share this post


Link to post
Share on other sites
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
}

Share this post


Link to post
Share on other sites
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); // lock

DWORD numVerts = D3DMesh()->GetNumVertices(); // total number of vertices

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

Share this post


Link to post
Share on other sites
Quote:
Original post by Claudio
While if I want to use the vertex buffer "D3DVB" ?



*** Source Snippet Removed ***

Is correct ?
Yes.

Quote:
Original post by Claudio
Appear error about "access violation to..."
Because you're not checking return values. What do the Debug Runtimes say?

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!