for (int i = 0, n = triangleArray.getIndexCount(), triangleIndex = 0; i < n; i += 3) {
triangleIndex = exportIndexedTriangle(triangleArray, i, i + 1, i + 2,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
}
} else if (geometryArray instanceof IndexedQuadArray) {
IndexedQuadArray quadArray = (IndexedQuadArray)geometryArray;
for (int i = 0, n = quadArray.getIndexCount(), triangleIndex = 0; i < n; i += 4) {
triangleIndex = exportIndexedTriangle(quadArray, i, i + 1, i + 2,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
triangleIndex = exportIndexedTriangle(quadArray, i, i + 2, i + 3,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
}
} else if (geometryArray instanceof IndexedLineStripArray) {
IndexedLineStripArray lineStripArray = (IndexedLineStripArray)geometryArray;
for (int initialIndex = 0, lineIndex = 0, strip = 0; strip < stripVertexCount.length; strip++) {
for (int i = initialIndex, n = initialIndex + stripVertexCount [strip] - 1;
i < n; i++, lineIndex += 2) {
exportIndexedLine(lineStripArray, i, i + 1, verticesIndices, lineIndex);
}
initialIndex += stripVertexCount [strip];
}
} else if (geometryArray instanceof IndexedTriangleStripArray) {
IndexedTriangleStripArray triangleStripArray = (IndexedTriangleStripArray)geometryArray;
for (int initialIndex = 0, triangleIndex = 0, strip = 0; strip < stripVertexCount.length; strip++) {
for (int i = initialIndex, n = initialIndex + stripVertexCount [strip] - 2, j = 0;
i < n; i++, j++) {
if (j % 2 == 0) {
triangleIndex = exportIndexedTriangle(triangleStripArray, i, i + 1, i + 2,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
} else { // Vertices of odd triangles are in reverse order
triangleIndex = exportIndexedTriangle(triangleStripArray, i, i + 2, i + 1,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
}
}
initialIndex += stripVertexCount [strip];
}
} else if (geometryArray instanceof IndexedTriangleFanArray) {
IndexedTriangleFanArray triangleFanArray = (IndexedTriangleFanArray)geometryArray;
for (int initialIndex = 0, triangleIndex = 0, strip = 0; strip < stripVertexCount.length; strip++) {
for (int i = initialIndex, n = initialIndex + stripVertexCount [strip] - 2;
i < n; i++) {
triangleIndex = exportIndexedTriangle(triangleFanArray, initialIndex, i + 1, i + 2,
verticesIndices, normalsIndices, uvsIndices, triangleIndex, vertices, exportedTriangles);
}
initialIndex += stripVertexCount [strip];
}
}
}
if (normalsIndices != null && !Arrays.equals(verticesIndices, normalsIndices)
|| uvsIndices != null && !Arrays.equals(verticesIndices, uvsIndices)) {
// Remove indirection in verticesIndices, normals and uvsIndices
// because SunFlow use only verticesIndices
float [] directVertices = new float [verticesIndices.length * 3];
float [] directNormals = normalsIndices != null
? new float [verticesIndices.length * 3]
: null;
float [] directUvs = uvsIndices != null
? new float [verticesIndices.length * 2]
: null;
int verticeIndex = 0;
int normalIndex = 0;
int uvIndex = 0;
for (int i = 0; i < verticesIndices.length; i++) {
int indirectIndex = verticesIndices [i] * 3;
directVertices [verticeIndex++] = vertices [indirectIndex++];
directVertices [verticeIndex++] = vertices [indirectIndex++];
directVertices [verticeIndex++] = vertices [indirectIndex++];
if (normalsIndices != null) {
indirectIndex = normalsIndices [i] * 3;
directNormals [normalIndex++] = normals [indirectIndex++];
directNormals [normalIndex++] = normals [indirectIndex++];
directNormals [normalIndex++] = normals [indirectIndex++];
}
if (uvsIndices != null) {
indirectIndex = uvsIndices [i] * 2;
directUvs [uvIndex++] = uvs [indirectIndex++];
directUvs [uvIndex++] = uvs [indirectIndex++];
}
verticesIndices [i] = i;
}
vertices = directVertices;
normals = directNormals;
uvs = directUvs;
}
} else {
if (geometryArray instanceof LineArray) {
LineArray lineArray = (LineArray)geometryArray;
for (int i = 0, n = lineArray.getVertexCount(); i < n; i += 2) {
exportLine(lineArray, i, i + 1, verticesIndices, i);
}
} else {
if (geometryArray instanceof TriangleArray) {
TriangleArray triangleArray = (TriangleArray)geometryArray;
for (int i = 0, n = triangleArray.getVertexCount(), triangleIndex = 0; i < n; i += 3) {
triangleIndex = exportTriangle(triangleArray, i, i + 1, i + 2,
verticesIndices, triangleIndex, vertices, exportedTriangles);
}
} else if (geometryArray instanceof QuadArray) {
QuadArray quadArray = (QuadArray)geometryArray;
for (int i = 0, n = quadArray.getVertexCount(), triangleIndex = 0; i < n; i += 4) {
triangleIndex = exportTriangle(quadArray, i, i + 1, i + 2,
verticesIndices, triangleIndex, vertices, exportedTriangles);
triangleIndex = exportTriangle(quadArray, i + 2, i + 3, i,
verticesIndices, triangleIndex, vertices, exportedTriangles);
}