Skip to content

Commit

Permalink
Implemented correct handling of "/" in .OBJ files
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudomanifold committed Jun 11, 2010
1 parent d9ec895 commit 6f0da7d
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,43 @@ bool mesh::load_obj(std::istream &in)
}
else if(keyword == OBJ_KEY_FACE)
{
std::vector<vertex*> vertices;

// Check whether it is a triplet data string
if(line.find_first_of('/') != std::string::npos)
{
// FIXME: NYI
while(!converter.eof())
{
std::string index_str;
converter >> index_str;

if(index_str.length() == 0)
continue;

size_t slash_pos = index_str.find_first_of('/'); // only interested in first occurrence

// Contains the index as a string (not
// including the '/'). The other
// attributes (normals, textures
// coordinates) are _removed_ here.
std::istringstream index_conv(index_str.substr(0, slash_pos));

long index = 0;
index_conv >> index;

if(index < 0)
{
std::cerr << "psalm: Handling of negative indices not yet implemented.\n";
return(false);
}
else
vertices.push_back(get_vertex(index-1));
}

add_face(vertices);
}
else
{
std::vector<vertex*> vertices;

long index = 0;
while(!converter.eof())
{
Expand Down

0 comments on commit 6f0da7d

Please sign in to comment.