Archived

This topic is now archived and is closed to further replies.

zander76

DXVertexBuffers

Recommended Posts

zander76    122
Hello everybody. I am working on getting all the vertex information out of a model loaded by DX. I am finally getting close, but i have a bug somewere that does not alow this to work.. Can anybody see what i am doing wrong. Thanks in advanced for any help. LPD3DXMESH mMeshBuffer; hr = D3DXLoadMeshFromX( fileName, D3DXMESH_DYNAMIC, device, NULL, NULL, NULL, &mMeshBuffer // The mesh buffer ); if (FAILED(hr)) { mApp->getAppWindow()->messageBox((char*)DXGetErrorString8(hr), "Mesh loading error"); } DWORD numVerts = mMeshBuffer->GetNumVertices(); DWORD numFaces = mMeshBuffer->GetNumFaces(); float* MeshArray = new float[numVerts]; float* TextureArray = new float[numFaces*3*2]; unsigned short* IndexArray = new unsigned short[numFaces*3]; LPDIRECT3DVERTEXBUFFER8 pVBuf; if (SUCCEEDED(mMeshBuffer->GetVertexBuffer(&pVBuf))) { CUSTOMVERTEX *pVert; if (SUCCEEDED(pVBuf->Lock(0,0,(BYTE **) &pVert,D3DLOCK_DISCARD))) { int meshCount = 0; int textureCount = 0; for (unsigned int i=0;ix; MeshArray[meshCount++] = pVert->y; MeshArray[meshCount++] = pVert->z; TextureArray[textureCount++] = pVert->tu; TextureArray[textureCount++] = pVert->tv; pVert++; } pVBuf->Unlock(); } pVBuf->Release(); } LPDIRECT3DINDEXBUFFER8 pIndBuf; hr = mMeshBuffer->GetIndexBuffer(&pIndBuf); if ( FAILED(hr)) { mApp->getAppWindow()->messageBox((char*)DXGetErrorString8(hr), "Mesh loading error"); } else { WORD *pInd; if (SUCCEEDED(pIndBuf->Lock(0, 0 ,(BYTE **)&pInd, D3DLOCK_DISCARD))) { for (unsigned int i=0;iUnlock(); } pIndBuf->Release(); } mesh->setVertexList(&MeshArray[0], numVerts); mesh->setTextureCoord(&TextureArray[0]); mesh->setIndexList(&IndexArray[0], numFaces*3); mesh->setTextureId( mApp->getImageManager()->LoadImage("textures/tiger.bmp") ); The problem seem to be something related to the indicies. Thanks again.. Ben

Share this post


Link to post
Share on other sites