Implement A New Modifier

Case Study: CollapseVertexModifier.cpp

This is a simple modifier that implements vertex collapsing. This modifier is used to simplify geometry by removing vertices and serves as a "delete vertex feature". However since this algorithm works on a winged edge mesh there are some important conditions.

Source Code

Please right click to download source code for this example.

Explanation

This modifier is simple to understand. The data interface is quite skeletal and used only to facilitate a scripted create command. There is no specific property sheet for this modifier because the modifier has no additional parameters beyond the parameters from the super-class modifier. The create command is implemented via script in modifier_scripts.ssl

Key Points

The vertex collapse algorithm performs vertex collapse operations in series because the results of one vertex collapse may affect the results of any subsequent vertex collapses. This is a key concept when writing modifiers: serial operation -vs- rare cases of parallel operation. Each stage of a modifier changes the mesh but you can test if the items in the selection are connected to each other and operate independently on each item on items that are not connected. Specific steps in this algorithm are as follows:

  1. Iterate the selection-set.
  2. Derive the edge-set for vertex 1.
  3. This edge-set is the "spoke edges" radiating from the vertex.
  4. The selected vertex is common to all the spoke edges.
  5. Derive all the vertices in the spoke-edge-set that are not selected.
  6. This is the spoke-vertex-set. Each spoke-edge-vertex is at the end of the spoke edge.
  7. To ensure geometric integrity we have to connect the spoke edge vertices.
  8. Connect the spoke-edge-vertex set from v1 to v2, v2 to v3, v3 to v4 ... and from v4 to v1.
  9. This forms a convex and completely contiguous border-edge-set around the selected vertex.
  10. For the selected vertex, collapse the first spoke-edge.
  11. This removes the vertex.