So I'm writing a Wavefront OBJ loader. I was able to get the vertex, normals, and texture coordinates, but I'm having problems with the faces. I'm trying to figure how to ignore certain characters, like "//" and "/" in C++ using std::stringstream. Is there anyway to do this? Thanks.
Here's my load function:
bool Model::load(std::string file_name) {
std::string line;
std::ifstream file(file_name.c_str());
if(file.is_open())
{
while(std::getline(file, line))
{
std::stringstream stream(line);
stream >> line;
if(line == "#")
{
// ignore.
}
if(line == "v") // vertices
{
double x, y, z;
stream >> x >> y >> z;
v.push_back(x);
v.push_back(y);
v.push_back(z);
#ifdef DEBUG
std::cout << "v " << x << " "<< y << " " << z << "\n";
#endif
}
if(line == "vt") // texture coordinates
{
double u, v;
stream >> u >> v;
vt.push_back(u);
vt.push_back(v);
#ifdef DEBUG
std::cout << "vt " << u << " "<< v << "\n";
#endif
}
if(line == "vn") // normals
{
double x, y, z;
stream >> x >> y >> z;
vn.push_back(x);
vn.push_back(y);
vn.push_back(z);
#ifdef DEBUG
std::cout << "vn " << x << " "<< y << " " << z << "\n";
#endif
}
if(line == "f")
{
short a, b, c;
stream >> a; stream >> b; stream >> c;
a--; b--; c--;
f.push_back(a);
f.push_back(b);
f.push_back(c);
std::cout << a << " " << b << " " << c << "\n";
}
}
file.close();
return true;
} return false;
}