Reputation: 73
By Using D3DXLoadMeshFromX, I could load a mesh's subsets, materials, textures,... So I succeed Draw Mesh.
What I want to know is that Mesh's Vertex Infomation(for picking).
My Code is..
m_pMesh->PDIRECT3DVERTEXBUFFER9 pVB;
m_pMesh->GetVertexBuffer(&pVB);
void* Vtx = nullptr;
pVB->Lock(0, 0, (void**)&Vtx, 0);
Then I want to know Vtx's information like Vertex, but Vtx is void pointer... If I know struct of that mesh I might know vertex info, but I don't
I'm sorry if I answer too vaguely.
Upvotes: 0
Views: 187
Reputation: 41127
This is covered in the legacy DirectX SDK's sample in Samples\C++\Direct3D\Pick
.
You have to use CloneMeshFVF
to reformat the vertex data layout and you need to make sure you specify D3DXMESH_VB_MANAGED
or D3DXMESH_VB_SYSTEMMEM
so that you can actually lock the resulting VB.
LPD3DXMESH pMesh;
g_Mesh.GetMesh()->CloneMeshFVF( D3DXMESH_MANAGED,
g_Mesh.GetMesh()->GetFVF(), pD3Device, &pMesh );
LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;
pMesh->GetVertexBuffer( &pVB );
pMesh->GetIndexBuffer( &pIB );
WORD* pIndices;
D3DVERTEX* pVertices;
pIB->Lock( 0, 0, ( void** )&pIndices, 0 );
pVB->Lock( 0, 0, ( void** )&pVertices, 0 );
Keep in mind that picking uses a CPU memory copy of the vertex data, while rendering uses a video memory copy. In real-time applications, you typically do not use the full complexity of the rendering model for collision, but a simplified collision model that you never need to render and only keep in memory.
Upvotes: 1