Trouble getting indices from a mesh

Started by
3 comments, last by Calin 18 years, 1 month ago
I'm trying to retrive vertex data from a mesh but can't get the vertex indices right. Here's the code I'm using:

UINT16 i0, i1, i2;
unsigned long TerrainFaceIndex;

D3DXIntersect( IntersPl.PlBottom.m_pMesh, &rayObjOrigin, &rayObjDirection, &HitBottom, &TerrainFaceIndex, &IntersPl.baryBottom.X, &IntersPl.baryBottom.Y, NULL, NULL, NULL);
Log("TerainFaceIndex %3.3ld \n", TerrainFaceIndex );



LPDIRECT3DINDEXBUFFER9 pIBx;
LPDIRECT3DVERTEXBUFFER9 pVBx;
IntersPl.PlBottom.m_pMesh->GetIndexBuffer(&pIBx);
IntersPl.PlBottom.m_pMesh->GetVertexBuffer(&pVBx);


WORD* pIndicesMs;
rslt=IntersPl.PlBottom.m_pMesh->LockIndexBuffer(D3DLOCK_READONLY, reinterpret_cast< VOID** >( &pIndicesMs ) );
if(FAILED(rslt)) { LogDX("Failed to Lock the Mesh IndexBuffer 'loading2.jpg' \n",rslt); }

i0 = pIndicesMs[TerrainFaceIndex * 3 + 0 ];
i1 = pIndicesMs[TerrainFaceIndex * 3 + 1 ];
i2 = pIndicesMs[TerrainFaceIndex * 3 + 2 ];
IntersPl.PlBottom.m_pMesh->UnlockIndexBuffer( );

Log("Face Index 1 %3.3d \n", i0);
Log("Face Index 2 %3.3d \n", i1);
Log("Face Index 3 %3.3d \n", i2);






The output in the Log file:

TerainFaceIndex 27778 
Face Index 1 39041 
Face Index 2 000 
Face Index 3 39042 
TerainFaceIndex 27525 
Face Index 1 000 
Face Index 2 7064 
Face Index 3 000 
TerainFaceIndex 27525 
Face Index 1 000 
Face Index 2 7064 
Face Index 3 000 
TerainFaceIndex 27522 
Face Index 1 7063 
Face Index 2 000 
Face Index 3 6934 
TerainFaceIndex 27522 
Face Index 1 7063 
Face Index 2 000 
Face Index 3 6934 






What am I doing wrong?

My project`s facebook page is “DreamLand Page”

Advertisement
hi,

isn't it possible that your mesh uses a 32 bit index buffer (D3DXMESH_32BIT), while you try to read it as 16 bit (WORD* pIndicesMs)?

kp
------------------------------------------------------------Neo, the Matrix should be 16-byte aligned for better performance!
My mesh loading call:
rslt = D3DXLoadMeshFromX(szMeshFile, D3DXMESH_MANAGED, pDevice, NULL,
&m_pMaterialsBuffer, NULL, &m_dwNumMaterials, &m_pMesh);
So, I guess it's a 16 bit mesh

My project`s facebook page is “DreamLand Page”

to get the vertex data forma my D3DXMESH, I first clone it unsing ID3DXMesh::CloneMeshFVF() to get a mesh with only vertex positions and indices so:

LPD3DXMESH originalMesh = NULL;
LPD3DXMESH tempMesh = NULL;
.
.
.
load the mesh into originalMesh
.
.
.
D3DXVECTOR3* vertex;
WORD* vIndex;
originalMesh->CloneMeshFVF(D3DXMESH_SYSTEMMEM, D3DFVF_XYZ, d3dDevice, &tempMesh);
tempMesh->LockVertexBuffer(D3DLOCK_READONLY, (BYTE**)&vertex);
tempMesh->LockIndexBuffer(D3DLOCK_READONLY, (BYTE**)&vIndex);

now I have all vertex positions inside 'vertex' and thier indices in 'vIndex'.
.
Quote:Original post by kovacsp
hi,

isn't it possible that your mesh uses a 32 bit index buffer (D3DXMESH_32BIT), while you try to read it as 16 bit (WORD* pIndicesMs)?

kp


Actually that was the cause of it. Thanks!

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement