genFace method

dynamic genFace(
  1. Map buffers,
  2. Map geoInfo,
  3. dynamic facePositionIndexes,
  4. dynamic materialIndex,
  5. dynamic faceNormals,
  6. dynamic faceColors,
  7. dynamic faceUVs,
  8. dynamic faceWeights,
  9. dynamic faceWeightIndices,
  10. dynamic faceLength,
)

Implementation

genFace(Map buffers, Map geoInfo, facePositionIndexes, materialIndex, faceNormals, faceColors, faceUVs, faceWeights,
    faceWeightIndices, faceLength) {
  for (var i = 2; i < faceLength; i++) {
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[0]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[1]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[2]]);

    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[(i - 1) * 3]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[(i - 1) * 3 + 1]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[(i - 1) * 3 + 2]]);

    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[i * 3]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[i * 3 + 1]]);
    buffers["vertex"].add(geoInfo["vertexPositions"][facePositionIndexes[i * 3 + 2]]);

    if (geoInfo["skeleton"] != null) {
      buffers["vertexWeights"].add(faceWeights[0]);
      buffers["vertexWeights"].add(faceWeights[1]);
      buffers["vertexWeights"].add(faceWeights[2]);
      buffers["vertexWeights"].add(faceWeights[3]);

      buffers["vertexWeights"].add(faceWeights[(i - 1) * 4]);
      buffers["vertexWeights"].add(faceWeights[(i - 1) * 4 + 1]);
      buffers["vertexWeights"].add(faceWeights[(i - 1) * 4 + 2]);
      buffers["vertexWeights"].add(faceWeights[(i - 1) * 4 + 3]);

      buffers["vertexWeights"].add(faceWeights[i * 4]);
      buffers["vertexWeights"].add(faceWeights[i * 4 + 1]);
      buffers["vertexWeights"].add(faceWeights[i * 4 + 2]);
      buffers["vertexWeights"].add(faceWeights[i * 4 + 3]);

      buffers["weightsIndices"].add(faceWeightIndices[0]);
      buffers["weightsIndices"].add(faceWeightIndices[1]);
      buffers["weightsIndices"].add(faceWeightIndices[2]);
      buffers["weightsIndices"].add(faceWeightIndices[3]);

      buffers["weightsIndices"].add(faceWeightIndices[(i - 1) * 4]);
      buffers["weightsIndices"].add(faceWeightIndices[(i - 1) * 4 + 1]);
      buffers["weightsIndices"].add(faceWeightIndices[(i - 1) * 4 + 2]);
      buffers["weightsIndices"].add(faceWeightIndices[(i - 1) * 4 + 3]);

      buffers["weightsIndices"].add(faceWeightIndices[i * 4]);
      buffers["weightsIndices"].add(faceWeightIndices[i * 4 + 1]);
      buffers["weightsIndices"].add(faceWeightIndices[i * 4 + 2]);
      buffers["weightsIndices"].add(faceWeightIndices[i * 4 + 3]);
    }

    if (geoInfo["color"] != null) {
      buffers["colors"].add(faceColors[0]);
      buffers["colors"].add(faceColors[1]);
      buffers["colors"].add(faceColors[2]);

      buffers["colors"].add(faceColors[(i - 1) * 3]);
      buffers["colors"].add(faceColors[(i - 1) * 3 + 1]);
      buffers["colors"].add(faceColors[(i - 1) * 3 + 2]);

      buffers["colors"].add(faceColors[i * 3]);
      buffers["colors"].add(faceColors[i * 3 + 1]);
      buffers["colors"].add(faceColors[i * 3 + 2]);
    }

    if (geoInfo["material"] != null && geoInfo["material"]["mappingType"] != 'AllSame') {
      buffers["materialIndex"].add(materialIndex);
      buffers["materialIndex"].add(materialIndex);
      buffers["materialIndex"].add(materialIndex);
    }

    if (geoInfo["normal"] != null) {
      buffers["normal"].add(faceNormals[0]);
      buffers["normal"].add(faceNormals[1]);
      buffers["normal"].add(faceNormals[2]);

      buffers["normal"].add(faceNormals[(i - 1) * 3]);
      buffers["normal"].add(faceNormals[(i - 1) * 3 + 1]);
      buffers["normal"].add(faceNormals[(i - 1) * 3 + 2]);

      buffers["normal"].add(faceNormals[i * 3]);
      buffers["normal"].add(faceNormals[i * 3 + 1]);
      buffers["normal"].add(faceNormals[i * 3 + 2]);
    }

    if (geoInfo["uv"] != null) {
      geoInfo["uv"].asMap().forEach((j, uv) {
        if (buffers["uvs"].length == j) buffers["uvs"].add([]);

        buffers["uvs"][j].add(faceUVs[j][0]);
        buffers["uvs"][j].add(faceUVs[j][1]);

        buffers["uvs"][j].add(faceUVs[j][(i - 1) * 2]);
        buffers["uvs"][j].add(faceUVs[j][(i - 1) * 2 + 1]);

        buffers["uvs"][j].add(faceUVs[j][i * 2]);
        buffers["uvs"][j].add(faceUVs[j][i * 2 + 1]);
      });
    }
  }
}