Hi everyone, sorry if this has been asked already (couldn't find it).
Anyway, I've parsed all of the data from a .obj file into float arrays (for verts, normals, texture-coords, and the face data aswell)
I've checked all the data against the actual file, so I don't think my parsing is a problem, but when I try to render the object (which is a cube) I just get 2 triangles. (Below, viewed from an angle)

I'm guessing that my problem is that I'm not doing anything with the face data and am just drawing the vertices.
If that is the case, could someone show me how to draw the faces aswell?
Here's my code:
The parse function of my OBJModel classtry {
while(((currentLine = file.readLine()) != null)) {
lineCount++;
currentLine = currentLine.trim();
if(currentLine.length() > 0) {
// Vertices
if(currentLine.charAt(0) == 'v' & currentLine.charAt(1) == ' ') {
String[] vertexCoordinatesString = currentLine.split("\\s+");
for(int i = 1; i < vertexCoordinatesString.length; i++) {
vertexArrayList.add(Float.valueOf(vertexCoordinatesString[i]).floatValue());
}
}
// Normals
if(currentLine.charAt(0) == 'v' & currentLine.charAt(1) == 'n') {
String[] normalCoordinatesString = currentLine.split("\\s+");
for(int i = 1; i < normalCoordinatesString.length; i++) {
vertexNormalsArrayList.add(Float.valueOf(normalCoordinatesString[i]).floatValue());
}
}
// Texture Coordinates
if(currentLine.charAt(0) == 'v' & currentLine.charAt(1) == 't') {
String[] textureCoordinatesString = currentLine.split("\\s+");
for(int i = 1; i < textureCoordinatesString.length; i++) {
vertexTextureCoordinatesArrayList.add(Float.valueOf(textureCoordinatesString[i]).floatValue());
}
}
if(currentLine.charAt(0) == 'f' & currentLine.charAt(1) == ' ') {
String[] faceCoordinatesString = currentLine.split("\\s+");
for(int i = 1; i < faceCoordinatesString.length; i++) {
String fixstring = faceCoordinatesString[i].replaceAll("//","/0/");
String[] tempstring = fixstring.split("/");
faceArrayList.add(Float.valueOf(tempstring[0]).floatValue());
if(tempstring.length > 1) {
faceTextureCoordinatesArrayList.add(Float.valueOf(tempstring[1]).floatValue());
}
else {
faceTextureCoordinatesArrayList.add(0.0f);
}
if(tempstring.length > 2) {
faceNormalsArrayList.add(Float.valueOf(tempstring[2]).floatValue());
}
else {
faceNormalsArrayList.add(0.0f);
}
}
}
}
}
// Convert ArrayLists to float[] arrays
// Vertices
vertices = new float[vertexArrayList.size()];
for (int i = 0; i < vertexArrayList.size(); i++) {
vertices[i] = vertexArrayList.get(i);
}
vertexNormals = new float[vertexNormalsArrayList.size()];
for (int i = 0; i < vertexNormalsArrayList.size(); i++) {
vertexNormals[i] = vertexNormalsArrayList.get(i);
}
vertexTextureCoordinates = new float[vertexTextureCoordinatesArrayList.size()];
for (int i = 0; i < vertexTextureCoordinatesArrayList.size(); i++) {
vertexTextureCoordinates[i] = vertexTextureCoordinatesArrayList.get(i);
}
// Faces
faces = new float[faceArrayList.size()];
for (int i = 0; i < faceArrayList.size(); i++) {
faces[i] = faceArrayList.get(i);
}
faceNormals = new float[faceNormalsArrayList.size()];
for (int i = 0; i < faceNormalsArrayList.size(); i++) {
faceNormals[i] = faceNormalsArrayList.get(i);
}
faceTextureCoordinates = new float[faceTextureCoordinatesArrayList.size()];
for (int i = 0; i < faceTextureCoordinatesArrayList.size(); i++) {
faceTextureCoordinates[i] = faceTextureCoordinatesArrayList.get(i);
}
}
The code I use to draw the objectpublic void Draw(Vector3f position, Vector3f rotation, Color colour) {
GL11.glTranslatef(position.x,position.y,position.z);
GL11.glRotatef(rotation.x, 1, 0, 0);
GL11.glRotatef(rotation.y, 0, 1, 0);
GL11.glRotatef(rotation.z, 0, 0, 1);
GL11.glColor3f(colour.r, colour.g, colour.b);
GL11.glBegin(GL11.GL_TRIANGLES);
for (int i = 0; i < model.vertices.length / 3; i++) {
GL11.glVertex3f(model.vertices[0 + 3 * i],model.vertices[1 + 3 * i],model.vertices[2 + 3 * i]);
}
GL11.glEnd();
}
Thanks

--
Daniel