in commons-geometry-io-euclidean/src/main/java/org/apache/commons/geometry/io/euclidean/threed/obj/ObjWriter.java [253:291]
private void writeFaceWithOffsets(final int vertexOffset, final int[] vertexIndices,
final int normalOffset, final int[] normalIndices) {
if (vertexIndices.length < EuclideanUtils.TRIANGLE_VERTEX_COUNT) {
throw new IllegalArgumentException("Face must have more than " + EuclideanUtils.TRIANGLE_VERTEX_COUNT +
" vertices; found " + vertexIndices.length);
} else if (normalIndices != null && normalIndices.length != vertexIndices.length) {
throw new IllegalArgumentException("Face normal index count must equal vertex index count; expected " +
vertexIndices.length + " but was " + normalIndices.length);
}
write(ObjConstants.FACE_KEYWORD);
int vertexIdx;
int normalIdx;
for (int i = 0; i < vertexIndices.length; ++i) {
vertexIdx = vertexIndices[i] + vertexOffset;
if (vertexIdx < 0 || vertexIdx >= vertexCount) {
throw new IndexOutOfBoundsException("Vertex index out of bounds: " + vertexIdx);
}
write(SPACE);
write(vertexIdx + 1); // convert to OBJ 1-based convention
if (normalIndices != null) {
normalIdx = normalIndices[i] + normalOffset;
if (normalIdx < 0 || normalIdx >= normalCount) {
throw new IndexOutOfBoundsException("Normal index out of bounds: " + normalIdx);
}
// two separator chars since there is no texture coordinate
write(ObjConstants.FACE_VERTEX_ATTRIBUTE_SEP_CHAR);
write(ObjConstants.FACE_VERTEX_ATTRIBUTE_SEP_CHAR);
write(normalIdx + 1); // convert to OBJ 1-based convention
}
}
writeNewLine();
}