Jump to content
  • Advertisement
lucky6969b

3D How to clip off vertices from a ID3DXMesh?

Recommended Posts

There are some unwanted vertexes on my mesh that I want to get rid of. If I just remove them from the vertex buffer, the index buffer is no longer correct. If I remove the indexes, the mesh is still not correct. How do I clip off the vertexes on my mesh that I don't want.
Direct3D 9
C++
thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement

Well, I assume you would have to recalculate the vertex and index buffers.

The best way I can see is to regenerate triangles from the original vertex and index buffers, remove the unwanted vertices/tris and then rebuild both buffers.

Share this post


Link to post
Share on other sites

Assuming you have a list of vertices and a list of indices, and you know exactly which vertices in the list you'd like to remove, you can write a fairly simple algorithm to reconstruct your vertex/index lists.

This can be done by using a map to map an index of your vertex list to an offset value which you'll use to correct the index list. First, loop through your vertex list and keep count of the current amount of vertices you've encountered that you'd like to remove. Whenever you hit a vertex that you don't want to remove, add an entry into the map which maps the current index (in the vertex list) to the current amount of vertices you've encountered so far that you want to remove. After you've done that, you can simple iterate over your index list and subtract the current value in the list by the value that you get from the map we made previously (using the current value in the index list as the key). This effectively "shifts" the indices over to correct for the vertices that you removed.

There's probably a better way of doing this, but I think this should correct all of the indices that you have, and now all you have to do is actually remove all of the vertices you don't want (and the indices that reference them) and create new vertex/index buffers with this new data.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!