Jump to content
  • Advertisement
Sign in to follow this  
ChaosPhoenix

Altering Vertex Buffers without knowing the Vertex Declaration before hand.

This topic is 3985 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 all, I'm trying to alter the vertices of a model that I read in from a 3DSMAX exporter. The API I'm using to read in the model allows me to grab the vertex declaration at run-time, but I'm not sure how I would use that information to set the position of each vert. This is for a heightmap so I need to be able to set the X,Y, and Z of each vert. I realize I would normally just make a vertex buffer but the system I'm using doesn't allow me direct D3D Device access so I have to go about it in this roundabout way. I know how to grab the position offset in the vertex declaration, but I'm unsure how I would use that information to specifically change the vertices when I lock the vertex buffer. Am I being clear enough? I have a vertex declaration, I have a position offset within that declaration, I need to know how to use that information to alter the vertices within my model after I lock the vertex buffer.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ChaosPhoenix
I have a vertex declaration, I have a position offset within that declaration, I need to know how to use that information to alter the vertices within my model after I lock the vertex buffer.
Something like:


void * buffPtr;
vBuff->Lock( 0, 0, &buffPtr, 0 );

for( int x = 0; x < vCount; ++x )
{
*( buffPtr + posOffset ) = newX[x];
*( buffPtr + posOffset + sizeof(float) ) = newY[x];
*( buffPtr + posOffset + sizeof(float) + sizeof(float) ) = newZ[x];

buffPtr += sizeof( vertexDecl );
}

vBuff->Unlock();

Perhaps?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kimani
Quote:
Original post by ChaosPhoenix
I have a vertex declaration, I have a position offset within that declaration, I need to know how to use that information to alter the vertices within my model after I lock the vertex buffer.
Something like:

*** Source Snippet Removed ***Perhaps?


That's what I thought it would end up looking like...just wondered if there was a more elegant way. Guess not. :/

Thanks though.

Share this post


Link to post
Share on other sites
Quote:
Original post by ChaosPhoenix
That's what I thought it would end up looking like...just wondered if there was a more elegant way. Guess not. :/

The .Net Framework offers Reflection for these kinds of situations, but I doubt you'd want to use .Net just for this feature. Additionally, it probably wouldn't perform too well [smile].

Share this post


Link to post
Share on other sites
You could write it a bit more elegantly, but nothing much different in concept. Something like:


char * ptr;
vBuff->Lock( 0, 0, reinterpret_cast<void**>&ptr, 0 );
for (int i=0; i<vCount; i++)
{
D3DXVECTOR3 * v = reinterpret_cast<D3DXVECTOR3*>(ptr + posOffset);
v.x = newX;
...
ptr += vertexSize;
}


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!