mesh editor : use vertexbuffer or mesh?
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?
For LPD3DXMESH you can just call the method like so to get a vertex buffer (assuming direct x 9.0)
or you can just directly lock the vertex buffer using code similar to this
obviously your parameters would change, but that's basically it :)
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 changesm_pMesh->UnlockVertexBuffer();
obviously your parameters would change, but that's basically it :)
but when I use D3DXMesh to get vertexbuffer ,the number of vertex is fixed .
how can I add or del vertex or triangle?
how can I add or del vertex or triangle?
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement