An Easy Way to Find Polygon Mesh Corners: Vertex Neighbor Count

Houdini,Houdini Jishusitu,VEX

When you want to find the corners of a polygon mesh, an easy method is to count the number of neighbors each vertex has.

For example, in a 2x4 grid of points forming a square, the number of neighboring points for each vertex is as follows.

  • Corner points have 2 neighbors
  • Perimeter points (except corners) have 3 neighbors
  • Interior points have 4 neighbors

As an example, let's take a look at point P1 in the image below.

Point P1 is connected to two neighbors, P2 and P5. You might wonder, "Is P6 also connected to Point P1?" In fact, they don't share an edge, so in the polygon mesh structure, P6 is not considered a neighboring vertex.

Usage Example

Connects a Grid node to an Attribute Wrangle, and enter the VEX code shown below. You should see the only the corners turn red, even when you change the number or Rows or Columns.

if neighbourcount(0, @ptnum) == 2){
    @Cd = set(1, 0, 0);
}

Using the same approach, you can also identify the corner vertices of a cube. Each cube corner has exactly three edges, meaning it has three neighboring vertices. By selecting the points where neighbourcount() returns 3, you can easily isolate all eight cube corners.

if neighbourcount(0, @ptnum) == 3){
    @Cd = set(1, 0, 0);
}

This method works not only for squares but also for cubes.