Sign in to follow this  
dartainiar

mesh editor : use vertexbuffer or mesh?

Recommended Posts

I try to make my own mesh editor use directx9 in c++ Using vertexbuffer is easy to control every triangle in mesh but it is hard to interact with my mesh because I have to implement all interactive function. Using mesh is easy to control mesh with mouse input.but I don't know how to modify my mesh .Like to add or to del triangle ,move the vertex on mesh etc. If any one can tell me how to modify vertex and face in ID3DXMesh,or to transfer vertexbuffer into mesh,or better way?

Share this post


Link to post
Share on other sites
For LPD3DXMESH you can just call the method like so to get a vertex buffer (assuming direct x 9.0)

LPDIRECT3DVERTEXBUFFER9 meshVB;
m_pMesh->GetVertexBuffer(&meshVB);



or you can just directly lock the vertex buffer using code similar to this

VERTEX *vertices;
m_pMesh->LockVertexBuffer(D3DLOCK_DISCARD, (BYTE**)&vertices);
//do vertices changes
m_pMesh->UnlockVertexBuffer();



obviously your parameters would change, but that's basically it :)

Share this post


Link to post
Share on other sites
You would need to create a new mesh with the new number of vertices and/or faces.

D3DXCreateMesh() is the function to use.

Then lock the buffers of both, copy existing ones from old to new, and add the new ones to the new mesh.

Share this post


Link to post
Share on other sites
Quote:
Original post by DXnut
You would need to create a new mesh with the new number of vertices and/or faces.

D3DXCreateMesh() is the function to use.

Then lock the buffers of both, copy existing ones from old to new, and add the new ones to the new mesh.


Or, allocate enough space for your original mesh in advance. The way the "big" editors do this, is that they keep the editable mesh separate from the graphics system so as to allow unlimited flexibility in editing it, regardless of what system will be rendering it.

I recommend keeping an editable mesh in your own data structures (ie. not a d3d mesh), and creating a new d3d mesh when your data changes. For simple transformations, you don't need to re-create the renderable mesh as shaders can do the work for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this