Jump to content
  • Advertisement
Sign in to follow this  
Calin

Trouble getting indices from a mesh

This topic is 4483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!