Introduction
This article explains how to get the vertices from a mesh base object with Managed C++.
1. Create a custom vertex with only point and normals
public __value class CustomVertex{
public :
Vector3 p;
Vector3 n;
const static VertexFormats Format=(VertexFormat)
( VertexFormats::Position|VertexFormats::Normal);
};
2. Set an array of the custom vertex (it will be filled with the vertices of the base mesh created)
CustomVertex m_vMeshVertices[];
3. Set a DirectX 9.0 device
Device* m_pDevice;
4. Create the function which will get the vertices of the base mesh object
Mesh* pMesh; int nb __gc[]; CustomVertex v3; Array* pArr; CustomVertex* pMvr; int i;
pMesh=Mesh::Box(m_pDevice,0.1f,0.1f,0.1f);
nb=new int __gc[1];
__box CustomVertex* ovar = __box(v3);
nb[0]=pMesh->NumberVertices;
m_vMeshVertices=new CustomVertex[pMesh->NumberVertices];
pArr=pMesh->LockVertexBuffer(ovar->GetType(),LockFlags::None,nb);
for(i=0;iNumberVertices;i++)
{
pMvr= __try_cast(pArr->GetValue(i));
m_vMeshVertices[i].n=pMvr->n;
m_vMeshVertices[i].p=pMvr->p;
}
pMesh->UnlockVertexBuffer();
pMesh->Dispose();