private String [] exportNodeGeometry(Geometry geometry,
Transform3D parentTransformations,
TexCoordGeneration texCoordGeneration,
String objectNameBase) {
if (geometry instanceof GeometryArray) {
GeometryArray geometryArray = (GeometryArray)geometry;
// Create vertices indices array depending on geometry class
int [] verticesIndices = null;
int [] stripVertexCount = null;
if (geometryArray instanceof IndexedGeometryArray) {
if (geometryArray instanceof IndexedLineArray) {
verticesIndices = new int [((IndexedGeometryArray)geometryArray).getIndexCount()];
} else if (geometryArray instanceof IndexedTriangleArray) {
verticesIndices = new int [((IndexedGeometryArray)geometryArray).getIndexCount()];
} else if (geometryArray instanceof IndexedQuadArray) {
verticesIndices = new int [((IndexedQuadArray)geometryArray).getIndexCount() * 3 / 2];
} else if (geometryArray instanceof IndexedGeometryStripArray) {
IndexedTriangleStripArray geometryStripArray = (IndexedTriangleStripArray)geometryArray;
stripVertexCount = new int [geometryStripArray.getNumStrips()];
geometryStripArray.getStripIndexCounts(stripVertexCount);
if (geometryArray instanceof IndexedLineStripArray) {
verticesIndices = new int [getLineCount(stripVertexCount) * 2];
} else {
verticesIndices = new int [getTriangleCount(stripVertexCount) * 3];
}
}
} else {
if (geometryArray instanceof LineArray) {
verticesIndices = new int [((GeometryArray)geometryArray).getVertexCount()];
} else if (geometryArray instanceof TriangleArray) {
verticesIndices = new int [((GeometryArray)geometryArray).getVertexCount()];
} else if (geometryArray instanceof QuadArray) {
verticesIndices = new int [((QuadArray)geometryArray).getVertexCount() * 3 / 2];
} else if (geometryArray instanceof GeometryStripArray) {
GeometryStripArray geometryStripArray = (GeometryStripArray)geometryArray;
stripVertexCount = new int [geometryStripArray.getNumStrips()];
geometryStripArray.getStripVertexCounts(stripVertexCount);
if (geometryArray instanceof LineStripArray) {
verticesIndices = new int [getLineCount(stripVertexCount) * 2];
} else {
verticesIndices = new int [getTriangleCount(stripVertexCount) * 3];
}
}
}
if (verticesIndices != null) {
boolean line = geometryArray instanceof IndexedLineArray
|| geometryArray instanceof IndexedLineStripArray
|| geometryArray instanceof LineArray
|| geometryArray instanceof LineStripArray;
float [] vertices = new float [geometryArray.getVertexCount() * 3];
float [] normals = !line && (geometryArray.getVertexFormat() & GeometryArray.NORMALS) != 0
? new float [geometryArray.getVertexCount() * 3]
: null;
// Store temporarily exported triangles to avoid to add their opposite triangles
// (SunFlow doesn't render correctly a face and its opposite)
Set<Triangle> exportedTriangles = line
? null
: new HashSet<Triangle>(geometryArray.getVertexCount());
boolean uvsGenerated = false;
Vector4f planeS = null;
Vector4f planeT = null;
if (!line && texCoordGeneration != null) {
uvsGenerated = texCoordGeneration.getGenMode() == TexCoordGeneration.OBJECT_LINEAR
&& texCoordGeneration.getEnable();
if (uvsGenerated) {
planeS = new Vector4f();
planeT = new Vector4f();
texCoordGeneration.getPlaneS(planeS);
texCoordGeneration.getPlaneT(planeT);
}
}
float [] uvs;
if (uvsGenerated
|| (geometryArray.getVertexFormat() & GeometryArray.TEXTURE_COORDINATE_2) != 0) {
uvs = new float [geometryArray.getVertexCount() * 2];
} else {
uvs = null;
}
if ((geometryArray.getVertexFormat() & GeometryArray.BY_REFERENCE) != 0) {
if ((geometryArray.getVertexFormat() & GeometryArray.INTERLEAVED) != 0) {
float [] vertexData = geometryArray.getInterleavedVertices();
int vertexSize = vertexData.length / geometryArray.getVertexCount();
// Export vertices coordinates
for (int index = 0, i = vertexSize - 3, n = geometryArray.getVertexCount();
index < n; index++, i += vertexSize) {
Point3f vertex = new Point3f(vertexData [i], vertexData [i + 1], vertexData [i + 2]);
exportVertex(parentTransformations, vertex, index, vertices);
}
// Export normals
if (normals != null) {
for (int index = 0, i = vertexSize - 6, n = geometryArray.getVertexCount();
index < n; index++, i += vertexSize) {
Vector3f normal = new Vector3f(vertexData [i], vertexData [i + 1], vertexData [i + 2]);
exportNormal(parentTransformations, normal, index, normals);
}
}
// Export texture coordinates
if (texCoordGeneration != null) {
if (uvsGenerated) {
for (int index = 0, i = vertexSize - 3, n = geometryArray.getVertexCount();
index < n; index++, i += vertexSize) {
TexCoord2f textureCoordinates = generateTextureCoordinates(
vertexData [i], vertexData [i + 1], vertexData [i + 2], planeS, planeT);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
} else if (uvs != null) {
for (int index = 0, i = 0, n = geometryArray.getVertexCount();
index < n; index++, i += vertexSize) {
TexCoord2f textureCoordinates = new TexCoord2f(vertexData [i], vertexData [i + 1]);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
} else {
// Export vertices coordinates
float [] vertexCoordinates = geometryArray.getCoordRefFloat();
for (int index = 0, i = 0, n = geometryArray.getVertexCount(); index < n; index++, i += 3) {
Point3f vertex = new Point3f(vertexCoordinates [i], vertexCoordinates [i + 1], vertexCoordinates [i + 2]);
exportVertex(parentTransformations, vertex, index, vertices);
}
// Export normals
if (normals != null) {
float [] normalCoordinates = geometryArray.getNormalRefFloat();
for (int index = 0, i = 0, n = geometryArray.getVertexCount(); index < n; index++, i += 3) {
Vector3f normal = new Vector3f(normalCoordinates [i], normalCoordinates [i + 1], normalCoordinates [i + 2]);
exportNormal(parentTransformations, normal, index, normals);
}
}
// Export texture coordinates
if (texCoordGeneration != null) {
if (uvsGenerated) {
for (int index = 0, i = 0, n = geometryArray.getVertexCount(); index < n; index++, i += 3) {
TexCoord2f textureCoordinates = generateTextureCoordinates(
vertexCoordinates [i], vertexCoordinates [i + 1], vertexCoordinates [i + 2], planeS, planeT);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
} else if (uvs != null) {
float [] textureCoordinatesArray = geometryArray.getTexCoordRefFloat(0);
for (int index = 0, i = 0, n = geometryArray.getVertexCount(); index < n; index++, i += 2) {
TexCoord2f textureCoordinates = new TexCoord2f(textureCoordinatesArray [i], textureCoordinatesArray [i + 1]);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
}
} else {
// Export vertices coordinates
for (int index = 0, n = geometryArray.getVertexCount(); index < n; index++) {
Point3f vertex = new Point3f();
geometryArray.getCoordinate(index, vertex);
exportVertex(parentTransformations, vertex, index, vertices);
}
// Export normals
if (normals != null) {
for (int index = 0, n = geometryArray.getVertexCount(); index < n; index++) {
Vector3f normal = new Vector3f();
geometryArray.getNormal(index, normal);
exportNormal(parentTransformations, normal, index, normals);
}
}
// Export texture coordinates
if (texCoordGeneration != null) {
if (uvsGenerated) {
for (int index = 0, n = geometryArray.getVertexCount(); index < n; index++) {
Point3f vertex = new Point3f();
geometryArray.getCoordinate(index, vertex);
TexCoord2f textureCoordinates = generateTextureCoordinates(
vertex.x, vertex.y, vertex.z, planeS, planeT);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
} else if (uvs != null) {
for (int index = 0, n = geometryArray.getVertexCount(); index < n; index++) {
TexCoord2f textureCoordinates = new TexCoord2f();
geometryArray.getTextureCoordinate(0, index, textureCoordinates);
exportTextureCoordinates(textureCoordinates, index, uvs);
}
}
}