[SOLVED] reading indeces from D3DXMESH

Started by
3 comments, last by pp000 14 years, 10 months ago
Hi! I'm trying to get the Indeces from a D3DXMESH, but i cannot figure out how? I have tried to solve it on my own, but I realised I couldn't. As far as I came:

const BYTE* pIndexes;
DWORD* indeces;
mesh->LockIndexBuffer(D3DLOCK_READONLY, (void**)&pIndexes); 


mesh->UnlockIndexBuffer() ;
I hope you can help me. PS: sorry for my bad english language skills, im from austria (not australia) [Edited by - pp000 on June 18, 2009 2:32:17 PM]
Advertisement
Typically an index buffer will have 16-bit indices, in which case you should use an unsigned short* pointer instead of a BYTE* pointer. You can check for sure by calling GetDesc on the index buffer and checking the Format member of the D3DINDEXBUFFER_DESC.
i have a working solution i think , checks for the format 16 or 32 bit and gets the x,y,z in to a D3DXVECTOR3, if i find it i will post it
:)
thank you, that helped a lot, but ive got another problem now:

i have tried something that writes the indices into a textfile. and i have changed pIndeces from BYTE* to unsigned short*.

ofstream myfile;myfile.open ("test.txt");for (UINT j = 0; j < noOfIndices; ++j) {    const unsigned short* d = (const unsigned short*)pIndexes;    myfile << *d << "\n";    pIndexes++;}myfile << "end" << "\n";myfile.close();


ive looked into the .x file and the indices are:
0,3,2,1, 4,7,6,5, 8,11,10,9, 12, ...

but when i print them, i get (i have sorted/formatted it):
0,3,2,0,2,1,
4,7,6,4,6,5,
...

my question:
what am i doing wrong?

thank you
i solved it, thank you for helping me =)

here's the code i use:

		DWORD nFaces = mesh->GetNumFaces();		ofstream myfile;		myfile.open ("process.txt");		UINT count = 0;		for (UINT j = 0; j < nFaces*3; ++j) {			if (count != 2 && count != 3) {				const unsigned short* d = (const unsigned short*)pIndexes;				myfile << *d << "\n";			}			count++;			if (count == 6) {				count = 0;			}			pIndexes++;		}

This topic is closed to new replies.

Advertisement