Advertisement

How to clip off vertices from a ID3DXMesh?

Started by February 03, 2018 05:37 AM
2 comments, last by stale 6 years, 11 months ago

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

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.

Advertisement

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.

This topic is closed to new replies.

Advertisement