3

I am trying to cut a mesh in half or at least be able to delete faces from it in real-time. How to go about doing this i wonder?

Lock the vertex buffers, memset the selected face or vertex to 0, does not work for me. has anyone a solution or a tutorial on this i really want this feature in my program!

Cheers

jmgunn87
  • 31
  • 2

3 Answers3

3

Oh - that one is easy. There is no need to modify the mesh. D3D can already do this for you!

Set the clip-plane via IDirect3DDevice9::SetClipPlane, then enable the plane via the D3DRS_CLIPPLANEENABLE renderstate. You can even set multiple clip-planes at the same time if you want to..

Here is a link to the msdn-entry: http://doc.51windows.net/Directx9_SDK/?url=/directx9_sdk/graphics/reference/d3d/interfaces/idirect3ddevice9/setclipplane.htm

And if you do a google search on "D3D SetClipPlane" you will find lots of discussions and example codes how to use it.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
0

If you need to dynamically delete triangles from a mesh the best/fastest way is to use indexed triangles. When you create the index buffer, use the 'D3DUSAGE_DYNAMIC' flag. When you want to delete triangles, lock it with the 'D3DLOCK_DISCARD' flag. Write the entire new list of indices into the buffer, leaving out the triangles you want to delete.

The index buffer will be much smaller than the vertex buffer, so re-uploading only indices won't be as much of a drag on the system as the vertex buffer would be. But if it would be a big problem for you to convert to indexed triangle lists, then doing these stame operations using the vertex buffer instead is probably your next best option.

Alan
  • 4,897
  • 2
  • 24
  • 17
0

You say that setting the vertex to 0 doesn't work. In what way doesn't it work?

If you set the position of all the verticies of a triangle to (0.0, 0.0, 0.0) then the resulting triangle will be of zero size and shouldn't be drawn. Just to be sure you could set it to an offscreen position instead of zero.

jcoder
  • 29,554
  • 19
  • 87
  • 130