bugfixes in the OBJ parser

metadata
Wenzel Jakob 2010-11-30 18:57:20 +01:00
parent 68b72fbe60
commit 2d21bd45e2
1 changed files with 5 additions and 4 deletions

View File

@ -37,9 +37,10 @@ public:
unsigned int uv[3]; unsigned int uv[3];
}; };
void fetch_line(std::istream &is, std::string &line) { bool fetch_line(std::istream &is, std::string &line) {
/// Fetch a line from the stream, while handling line breaks with backslashes /// Fetch a line from the stream, while handling line breaks with backslashes
std::getline(is, line); if (!std::getline(is, line))
return false;
int lastCharacter = line.size()-1; int lastCharacter = line.size()-1;
while (lastCharacter >= 0 && while (lastCharacter >= 0 &&
(line[lastCharacter] == '\r' || (line[lastCharacter] == '\r' ||
@ -55,6 +56,7 @@ public:
} else { } else {
line.resize(lastCharacter+1); line.resize(lastCharacter+1);
} }
return true;
} }
WavefrontOBJ(const Properties &props) : Shape(props) { WavefrontOBJ(const Properties &props) : Shape(props) {
@ -95,8 +97,7 @@ public:
std::set<std::string> geomNames; std::set<std::string> geomNames;
int geomIdx = 0; int geomIdx = 0;
while (is.good() && !is.eof()) { while (is.good() && !is.eof() && fetch_line(is, line)) {
fetch_line(is, line);
std::istringstream iss(line); std::istringstream iss(line);
if (!(iss >> buf)) if (!(iss >> buf))
continue; continue;