javajavafxmeshface

What does the face list actually store


I understand that in a triangle mesh in JavaFX you have points and texture coordinates, but what is actually stored in the faces array. If I have the following points and texture points for a rectangle:

    float[] points = {
          -width/2,  height/2, 0, // idx p0
          -width/2, -height/2, 0, // idx p1
          width/2,  height/2, 0, // idx p2
          width/2, -height/2, 0  // idx p3
      };
      float[] texCoords = {
          1, 1, // idx t0
          1, 0, // idx t1
          0, 1, // idx t2
          0, 0  // idx t3
      };

what should the faces array be and why?

Also, I have seen some examples where they seem to repeat the same point in the faces array, like below, why is this?

int[] faces = {
                   2, 2, 1, 1, 0, 0,
                   2, 2, 3, 3, 1, 1
              };

Solution

  • Your array

    int[] faces = {
        2, 2, 1, 1, 0, 0,
        2, 2, 3, 3, 1, 1
    };
    

    is mapping your points xyz to uv texture coordinates and wiring two triangle faces. If you replace the variables with the naming comments your array will be like this:

    int[] faces = {
        idx p2, idx t2, idx p1, idx t1, idx p0, idx t0,
        idx p2, idx t2, idx p3, idx t3, idx p1, idx t1
    };