Modulo for Mesh Triangle Vertice Indices?

I remember seeing a code example with a modulo operator being used to combine the corner vertices (indices) of mesh triangle face (index combinations: 0,1 - 1,2 - 2,0) but I can’t remember that formula. I think it was a code example by @DanielPiker but it could have been someone else.

The code I resorted to use for this purpose looks just too ugly:

    var index = -1;
    var v_i = mesh.Faces.GetTopologicalVertices(i);          
    if (GetClosestEdgeIndex(mid_pt, v_i[0], v_i[1], out index))
        ne_indices[edge_cnt] = index;
    else if (GetClosestEdgeIndex(mid_pt, v_i[1], v_i[2], out index))
        ne_indices[edge_cnt] = index;
    else if (GetClosestEdgeIndex(mid_pt, v_i[2], v_i[0], out index))
        ne_indices[edge_cnt] = index;

It would be more compact using the modulo approach instead.

// Rolf

I found it, and well, at least it looks more sophisticated:

    var v_i = mesh.Faces.GetTopologicalVertices(i);
    for (int k = 0; k < v_i.Length; k++)  {
        var index = -1;
        if (GetClosestEdgeIndex(mesh, mid_pt, v_i[k], v_i[(k + 1) % v_i.Length], out index)) {
          ne_indices[i] = index; break;
        }
    }

// Rolf

For going back

1 Like