View Full Version : .X mesh indexbuffer help
Anddos
03-15-2008, 04:29 AM
i am trying to get each X,Y,Z of the index buffer , i want the same as when you get the GetvertexBuffer but that has random points so that its alot harder to draw a triangle strip on the mesh and see it in wireframe render state
after locking i cant think how you go through the data that was locked to get each X,Y,Z floats
Reedbeta
03-15-2008, 09:42 AM
The index buffer doesn't have XYZs, it just has indices into the vertex buffer. You need the XYZ locations stored in the vertex buffer, but accessed in the order dictated by the index buffer.
Anddos
03-15-2008, 11:07 AM
can you show me a sample?
Reedbeta
03-15-2008, 11:48 AM
It's really, really, simple. The index buffer is a list of integers. If the index buffer says 0, 2, 3, 1, ... that means the vertices are vbuffer[0], vbuffer[2], vbuffer[3], vbuffer[1], and so on...
Anddos
03-15-2008, 11:57 AM
It's really, really, simple. The index buffer is a list of integers. If the index buffer says 0, 2, 3, 1, ... that means the vertices are vbuffer[0], vbuffer[2], vbuffer[3], vbuffer[1], and so on...
and those indexs are stored as lpIB[0] , lpIB[1] , lpIB[2].......?
i cant seem to output it to a messagebox
sprintf(data , "%s %i" ,"lpIB[0]" , lpIB[0]);
MessageBox(NULL,data,"",0);
error C2109: subscript requires array or pointer type
Reedbeta
03-15-2008, 12:08 PM
Yes that's how ANY array works.
Anddos
03-15-2008, 12:36 PM
HRESULT D3DXMeshClass::ExtractVerticesFromIndexBuffer(LPD3 DXMESH Spaceship)
{
BYTE* lpbVb;
BYTE *lpIB;
//get the vertex buffer
cHresult = Spaceship->LockVertexBuffer( D3DLOCK_READONLY, (VOID**)&lpbVb );
if(cHresult == D3D_OK)
{
MessageBox(NULL,"Lock VerteBuffer Success","",0);
}
cHresult = Spaceship->LockIndexBuffer ( D3DLOCK_READONLY, (VOID**)&lpIB);
if(cHresult == D3D_OK)
{
MessageBox(NULL,"Lock IndexBuffer Success","",0);
}
cHresult = Spaceship->GetIndexBuffer( &lpIndexBuffer );
if(cHresult == D3D_OK)
{
MessageBox(NULL,"Get IndexBuffer Success","",0);
}
cHresult = lpIndexBuffer->GetDesc( &ibdesc );
if(cHresult == D3D_OK)
{
MessageBox(NULL,"GetDesc Success","",0);
}
if(ibdesc.Format == D3DFMT_INDEX32)
{
MessageBox(NULL,"ibdesc.Format 32","",0);
numIndices = ibdesc.Size / sizeof(DWORD);
}
else
{
MessageBox(NULL,"ibdesc.Format 16","",0);
numIndices = ibdesc.Size / sizeof(WORD);
}
numBytesPerVertex = Spaceship->GetNumBytesPerVertex();
for(int i=0; i<numIndices; i += 3 )
{
//sprintf(data, "%s %d" , "loop count" , i);
//MessageBox(NULL,data,"",0);
if (ibdesc.Format == D3DFMT_INDEX32 )
{
idxVbVert0 = ((DWORD*)lpIB)[ i ];
idxVbVert1 = ((DWORD*)lpIB)[ i+1 ];
idxVbVert2 = ((DWORD*)lpIB)[ i+2 ];
}
else
{
idxVbVert0 = ((WORD*)lpIB)[ i ];
idxVbVert1 = ((WORD*)lpIB)[ i+1 ];
idxVbVert2 = ((WORD*)lpIB)[ i+2 ];
}
D3DXVECTOR3 v0 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert0 * numBytesPerVertex ];
D3DXVECTOR3 v1 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert1 * numBytesPerVertex ];
D3DXVECTOR3 v2 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert2 * numBytesPerVertex ];
sprintf(data, "%s %f" , "v0.x" , v0.x);
MessageBox(NULL,data,"",0);
}
//Unlock()
Spaceship->UnlockVertexBuffer();
Spaceship->UnlockIndexBuffer();
return D3D_OK;
}
Anddos
03-16-2008, 01:43 AM
is this doing the right think now ?
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.