• Advertisement

Archived

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

Editing the vertex buffer

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

Hey. I checked the FAQ but I wasn't able to find something specifically answering this question, so... I have a mesh. Vanilla D3DXMESH on DirectX 9. What I want to do is play around with the vertex buffer - right now all I'm trying to do is get it to translate it a bit in the X+ direction, just to test out playing with the VB. But, when I execute my code, the mesh like...explodes into a bunch of shards. It's kind of cool looking, but it's not exactly what I was interested in. The code goes like this (a mesh zmMesh is given):
	LPDIRECT3DVERTEXBUFFER9 vbMesh;
	zmMesh->GetVertexBuffer(&vbMesh);

	D3DVERTEXBUFFER_DESC vbDesc;
	vbMesh->GetDesc( &vbDesc );

	zmMesh->LockVertexBuffer( NULL, (void**) &vbMesh)

	BYTE* pData = (BYTE*) vbMesh;

	CZenVertex* VertexArray = (CZenVertex*) pData;

	UINT Offset = 0;

	while( Offset < vbDesc.Size )
	{
		CZenVertex* ThisVertex = (CZenVertex*) (pData + Offset);
		ThisVertex->m_Position.x += 1;
		Offset += sizeof(CVertex);
	}

	zmMesh->UnlockVertexBuffer();  
I had a couple guesses why it wasn't working - like, maybe I have to work with the index buffer instead, or maybe because the mesh is D3DXMESH_DYNAMIC, or something. But I really have no idea what goes on in the VB. Perhaps there's an offset at the beginning of the VB I don't know about? [edited by - Metternich on May 7, 2004 1:12:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
I have never used the mesh object before, but I have used vertex buffers... I don''t know if this helps at all, but from your code it looks like LockVertexBuffer should be called on the vertex buffer you receive from the mesh, not on the mesh itself.

something like this instead (though I have made no attempt to be careful):

---------------------

BYTE* pData;

zmMesh->GetVertexBuffer(&vbMesh);

vbMesh->LockVertexBuffer( NULL, (void**) &pData);

while( Offset < vbDesc.Size )
{
...
}

vbMesh->UnlockVertexBuffer();

Share this post


Link to post
Share on other sites
Protemus is right. vbMesh is a Direct3DVertexBuffer9 pointer. You are just casting it into a BYTE pointer. vbMesh doesn''t just contain the vertex information though. It is an encapsulating class for the vertex information. When you call LockVertexBuffer from a Direct3DVertexBuffer9 class, you are telling it to give you the pointer to the vertex data that it encapsulates.

You probably already know all of this and it was just one of those oopsies. If not though, is there any further information you need?

Chris

Share this post


Link to post
Share on other sites
Wow. Speedy responses.

I tried it, and the exact same thing happened with the mesh splintering. Here''s my new code:

LPDIRECT3DVERTEXBUFFER9 vbMesh;
zmMesh->GetVertexBuffer(&vbMesh);
D3DVERTEXBUFFER_DESC vbDesc;
vbMesh->GetDesc( &vbDesc );
void* pData;

vbMesh->Lock(0,0, &pData, 0 );
CZenVertex* VertexArray = (CZenVertex*) pData;
for(UINT i = 0; i < vbDesc.Size / sizeof( CZenVertex ); i++)
{
VertexArray.m_Position.x += 1;
}
vbMesh->Unlock();

Share this post


Link to post
Share on other sites
How is that looping through each vertex?

Couldn't it be something like this:

Vertex->x += 1;

** EDIT **
More importantly can't you cast the data like this?

Vertex** array = (Vertex**)pdata;

for(int i=0; i < count; i++){
array[0]->x += 1;
}

** /EDIT **

[edited by - Nullmind on May 7, 2004 3:25:14 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by nullmind
How is that looping through each vertex?

Couldn't it be something like this:

Vertex->x += 1;

** EDIT **
More importantly can't you cast the data like this?

Vertex** array = (Vertex**)pdata;

for(int i=0; i < count; i++){
array[0]->x += 1;
}

** /EDIT **

[edited by - Nullmind on May 7, 2004 3:25:14 AM]


Yeah, that's what I had...it didn't show the brackets around it when I pasted it: :/

VertexArray[letter i].m_Position.x += 1;

This is probably a dumb question, but what's the advantage of casting it like that?

[edited by - Metternich on May 7, 2004 3:31:02 AM]

Share this post


Link to post
Share on other sites

  • Advertisement