Hi,
I'm trying to load an .obj model to OpenGL and I need to parse the file. What I've done until now:
v 0.000000 3.897879 -1.378193
v -0.309017 3.856391 -1.352228
vt 0.314607 0.256292
vt 0.226357 0.365001
vn -0.156435 0.837235 -0.523990
vn -0.309017 0.806183 -0.504556
f 13/3/45 14/6/46 24/29/47
f 24/29/47 14/6/46 25/31/48
So for the v / vt / vn the code source is:
std::vector<glm::vec3> vertex;
std::vector<glm::vec2> texture;
std::vector<glm::vec3> normals;
std::string lineStr;
while (inf)
{
getline(inf, lineStr);
//std::cout << "LINESTR: " << lineStr << std::endl;
if (lineStr[0] == 'v' && lineStr[1] == ' ')
{
std::stringstream os;
std::string unsused;
double posx, posy, posz;
os << lineStr;
os >> unsused >> posx >> posy >> posz;
std::cout << " Pos X: " << posx << " Pos Y: " << posy << " Pos Z: " << posz << std::endl;
vertex.push_back(glm::vec3(posx, posy, posz));
}
// The same source code is for vt and vn
}
It seems that it works. But I have some problems parsing the faces. I don't know exactly how to do it. Well I could use a lot of "if", but I'm not sure if this would be a good idea.
Any advices ?
Thank you!