Given the following rendered objects (dragon with completely white texture) and stall with a basic texture. What might be the error? Are my indices wrong? Are some vertices or faces wrong?
:
What could possibly be wrong in my obj-renderer class? I followed a tutorial and unfortunately my model does not look like the desired model. The dragon should be completely white without any black lines and the stall texture looks wrong (white lines which shouldn't be there).
This is the source-code (basic .obj-rendering with "v ", "vt ", "vn ", "f "):
try {
while ((line = reader.readLine()) != null && !line.startsWith("f ")) {
String[] currentLine = line.split(" ");
if (line.startsWith("v ")) {
Vector3f vertex =
new Vector3f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]),
Float.parseFloat(currentLine[3]));
vertices.add(vertex);
} else if (line.startsWith("vt ")) {
Vector2f texture =
new Vector2f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]));
textures.add(texture);
} else if (line.startsWith("vn ")) {
Vector3f normal =
new Vector3f(Float.parseFloat(currentLine[1]), Float.parseFloat(currentLine[2]),
Float.parseFloat(currentLine[3]));
normals.add(normal);
}
}
textureArray = new float[vertices.size() * 2];
normalsArray = new float[vertices.size() * 3];
do {
if (line == null || !line.startsWith("f ")) {
continue;
}
String[] currentLine = line.split(" ");
String[] vertex1 = currentLine[1].split("/");
String[] vertex2 = currentLine[2].split("/");
String[] vertex3 = currentLine[3].split("/");
processVertex(vertex1, indices, textures, normals, textureArray, normalsArray);
processVertex(vertex2, indices, textures, normals, textureArray, normalsArray);
processVertex(vertex3, indices, textures, normals, textureArray, normalsArray);
} while ((line = reader.readLine()) != null);
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
verticesArray = new float[vertices.size() * 3];
indicesArray = new int[indices.size()];
int vertexPointer = 0;
for (Vector3f vertex : vertices) {
verticesArray[vertexPointer++] = vertex.x;
verticesArray[vertexPointer++] = vertex.y;
verticesArray[vertexPointer++] = vertex.z;
}
for (int i = 0; i < indices.size(); i++) {
indicesArray[i] = indices.get(i);
}
return loader.loadToVao(verticesArray, textureArray, normalsArray, indicesArray);
}
private static void processVertex(final String[] vertexData, final List<Integer> indices,
final List<Vector2f> textures, final List<Vector3f> normals, final float[] textureArray,
final float[] normalsArray) {
int currentVertexPointer = Integer.parseInt(vertexData[0]) - 1;
indices.add(currentVertexPointer);
Vector2f currentTex = textures.get(Integer.parseInt(vertexData[1]) - 1);
textureArray[currentVertexPointer * 2] = currentTex.x;
textureArray[currentVertexPointer * 2 + 1] = 1 - currentTex.y;
Vector3f currentNorm = normals.get(Integer.parseInt(vertexData[2]) - 1);
normalsArray[currentVertexPointer * 3] = currentNorm.x;
normalsArray[currentVertexPointer * 3 + 1] = currentNorm.y;
normalsArray[currentVertexPointer * 3 + 2] = currentNorm.z;
}