Quote: Original post by badbrad29
i wasn't planning on saving the files as another format, but i just store them as vertexes and faces. i was just going to use them as they are. i need to do something different because this method is a pain in the ass. i have to edit the files before i can load them. i think i'm going to go with something closer to robs method so it will skip the unneeded lines, but i'm not sure. anyway does anyone know how to get the texture coordinates. i can't save textures with the files so i'm probably going to add an extra line to my obj file that has the adress of the texture and get the coordinates within the program, but how do i do this? i'm pretty new so if im asking an obvious question i'm sorry.
Dude your way is working as IM using it.
To read all obj files use you can skip bits in the readstr loop by adding:
if((lineBuffer[0] == '#') || (lineBuffer[0] == '\n') || (lineBuffer[0] == 'm') || (lineBuffer[0] == 'g') || (lineBuffer[0] == 's') || (lineBuffer[0] == 'u')) fgets(lineBuffer,512,objFile);
it leaves these to work with 'v', 'vn', 'vt', 'f' else bad format
dealing with vt and vn are the same as with v
if(lineBuffer[0] == 'v') { if(lineBuffer[1]=='t'){ fgets(lineBuffer,512,objFile); // Reads In The Next Line Of Text sscanf(lineBuffer, "%f%f", &ru, &rv); uvs[uvCount].u = ru, uvs[uvCount].v = rv, ++uvCount; } else if(lineBuffer[1]=='n'){ fgets(lineBuffer,512,objFile); // Reads In The Next Line Of Text sscanf(lineBuffer, "%f%f%f", &rx, &ry, &rz); normals[normalCount].x = rx, normals[normalCount].y = ry, normals[normalCount].z = rz, ++normalCount; } else{ fgets(lineBuffer,512,objFile); // Reads In The Next Line Of Text sscanf(lineBuffer, "%f%f%f", &rx, &ry, &rz); vertices[vertexCount].x = rx, vertices[vertexCount].y = ry, vertices[vertexCount].z = rz; ++vertexCount; } }
Faces will be the tricky bit..Ive got to do those next
Bear in mind that its probably bad code as IM a beginner too
-LW