Click here to Skip to main content
Licence CPOL
First Posted 6 Apr 2004
Views 36,603
Bookmarked 14 times

Get vertices from a mesh base object with Managed C++

By | 6 Apr 2004 | Article
How to get the vertices from a mesh base object with Managed C++.

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;   //The mesh object from witch we will get vertices
int nb __gc[];  //Use it to get the number of vertice
CustomVertex v3; //Use it for GetType() in LockVertexBuffer
Array* pArr;      //Use it for the result of LockVertexBuffer
CustomVertex* pMvr; //Use it for the cast of the Array* to CustomVertex*
int i;
// Create a mesh base object : a box for example
pMesh=Mesh::Box(m_pDevice,0.1f,0.1f,0.1f); 
//Format nb and v3 to be used with LockVertexBuffer
nb=new int __gc[1];
__box CustomVertex* ovar = __box(v3);
//Get the nubmer of vertices of the mesh
nb[0]=pMesh->NumberVertices;
//Init our array of vertices 
m_vMeshVertices=new CustomVertex[pMesh->NumberVertices];
//Lock the vertex buffer
pArr=pMesh->LockVertexBuffer(ovar->GetType(),LockFlags::None,nb);
//Copy vertices to our array
for(i=0;i<pmesh- />NumberVertices;i++)
{
     pMvr= __try_cast<customvertex* />(pArr->GetValue(i));
     m_vMeshVertices[i].n=pMvr->n;
     m_vMeshVertices[i].p=pMvr->p;
}
//Unlock the vertex buffer and free the mesh
pMesh->UnlockVertexBuffer();

pMesh->Dispose();

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

actis

Web Developer

France France

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthanx alot...and a suggestion... Pinmemberqod1:30 16 Apr '04  
GeneralGuide PinmemberJohann Gerell0:31 7 Apr '04  
GeneralLess would have been more PinmemberFranz Brunner23:20 6 Apr '04  
GeneralRe: Less would have been more PinsitebuilderErik Thompson6:57 7 Apr '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 7 Apr 2004
Article Copyright 2004 by actis
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid