Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Copy index buffer from ID3DXMesh to seperate index buffer

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

Basically I am trying to load a .X file into a ID3DXMesh, then copy all the information into seperate buffers, i.e. verticies into vertex buffer, tex coords into vertex buffer and indicies into an index buffer. I am fairly certain I am copying the verticies and texture coordinates correctly, I am just not sure how to do the indicies. This is how I am copying the indicies now (which is obviously not the right way to do it):
typedef struct {
		short IBNumber[3];
} IndexBufferStruct;

char *AnimatedMesh1IBPtr, AnimatedMesh1TempIBPtr;

AnimatedMesh1->LockIndexBuffer(D3DLOCK_READONLY, (void**)&AnimatedMesh1IBPtr);
ModelIB->Lock(0 ,0, (void**)&AnimatedMesh1TempIBPtr, 0);

for(DWORD i=0; i < NumberOfTriangles; i++)
{
	IndexBufferStruct *AnimatedMesh1IBStruct = (IndexBufferStruct*)AnimatedMesh1IBPtr;
	IndexBufferStruct *AnimatedMesh1TempIBStruct = (IndexBufferStruct*)AnimatedMesh1TempIBPtr;

	AnimatedMesh1TempIBStruct->IBNumber[0] = AnimatedMesh1IBStruct->IBNumber[0];
	AnimatedMesh1TempIBStruct->IBNumber[1] = AnimatedMesh1IBStruct->IBNumber[1];
	AnimatedMesh1TempIBStruct->IBNumber[2] = AnimatedMesh1IBStruct->IBNumber[2];

	AnimatedMesh1IBPtr += sizeof(IndexBufferStruct);
	AnimatedMesh1TempIBPtr += sizeof(IndexBufferStruct);
}

AnimatedMesh1->UnlockIndexBuffer();
ModelIB->Unlock();

Thanks, -Chris

Share this post


Link to post
Share on other sites
Advertisement
typedef struct {
WORD IBNumber[3];
} IndexBufferStruct;

IndexBufferStruct *IBto, *IBfrom;

AnimatedMesh1->LockIndexBuffer(D3DLOCK_READONLY, (void**)&IBfrom);
ModelIB->Lock(0 ,0, (void**)&IBto, 0);

for(DWORD i=0; i < NumberOfTriangles; i++)
{
IBto = IBfrom;
}

AnimatedMesh1->UnlockIndexBuffer();
ModelIB->Unlock();

Of course, this assumes your mesh is using 16 bit indices.

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!