views:

332

answers:

4

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

+2  A: 

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
A: 

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
A: 

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.

John Burton
A: 

thanks for the help so far.

Accessing the tri's by index has worked properly.

I am still wondering how i can add blood splatters to individual tri's on the mesh? i have tried to mimick the mesh's vertex structure, locking the buffers and modifying the diffuse color but that makes the vertex extrude in a weird manner.

Also, can ClipPlane split my mesh into 2 mesh objects?

I am working on a simple gore engine for my characters in game.

thanks.

jmgunn87
A clip plane will prevent any tris on one side of the plane from rendering. If you wanted to draw both halves in different places, then you could draw twice, inverting the clip plane.
Alan
Modifying the diffuse color should work, so you might want to check that you are writing to the correct offsets. It may or may not give you a good blood splatter effect though. Search for information on projected texturing. You can draw a small blood splatter texture on an extra batch of vertices using projected texture coordinates.
Alan