Sign in to follow this  
PhiberOptic

Extracting data from Indexbuffer / XMesh

Recommended Posts

PhiberOptic    128
Hi there. I got a question for you guys! I'm using D3D9 and writing a little 3d app. I'm using the built in D3DX mesh tools to load a simple static mesh from a x-file. The problem I got is that I want to access individually faces to do some math / sorting manually. To do that I will require the vertexbuffer copied to my own stucture (wich I have done) then I also need the data from the indexbuffer, but I don't know how to access it. I wrote this code:
	struct looseIB
	{
		WORD i[3];
	};
	looseIB* pIB = new looseIB[ numFaces ];
	void* pCpy = NULL;
	mesh->LockIndexBuffer(0,(void**)&pCpy);
		memcpy(pIB,pCpy,sizeof(looseIB)*numFaces);
	mesh->UnlockIndexBuffer();	

But it didn't work, the pIB is filled with "bullshit". I tried to change to DWORD i[3]; also. Do anyone know how to do this? Do I have to add other members to my struct or something? Thanks

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Have you turned up D3D/D3DX debug output?

I can't see anything obviously wrong with your fragment, but the debug output might well be warning/hinting as to why the call isn't doing what you want it to [smile]

hth
Jack

Share this post


Link to post
Share on other sites
PhiberOptic    128
I solved it. The xfile contained 4 vertex / face so, when I made a mesh with triangles, my code actually worked! :)

However, how do one know when to handle 4verts/face or 3 verts/face.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by PhiberOptic
However, how do one know when to handle 4verts/face or 3 verts/face.


Never tried it, but presumably ID3DXMesh::GetNumVertices( ) divided by ID3DXMesh::GetNumFaces( ) would give you 3 or 4 accordingly...

Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this