Altering Vertex Buffers without knowing the Vertex Declaration before hand.
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.
Quote:Original post by ChaosPhoenixSomething like:
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.
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();
Quote:Original post by KimaniQuote:Original post by ChaosPhoenixSomething like:
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.
*** 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.
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].
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;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement