Sign in to follow this  
pp000

[SOLVED] reading indeces from D3DXMESH

Recommended Posts

pp000    127
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]

Share this post


Link to post
Share on other sites
MJP    19754
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.

Share this post


Link to post
Share on other sites
Anddos    588
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

Share this post


Link to post
Share on other sites
pp000    127
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

Share this post


Link to post
Share on other sites
pp000    127
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++;
}

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