diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index 9cdc507e3cc..da8b51f9af6 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -72,12 +73,30 @@ bool read_OBJ(std::istream& is, bool tex_found(false), norm_found(false); while(getline(is, line)) { - if(line.empty()) - continue; + // get last non-whitespace, non-null character + auto last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); }); + if(last == line.rend()) + continue; // line is empty or only whitespace + + // keep reading lines as long as the last non-whitespace, non-null character is a backslash + while(last != line.rend() && *last == '\\') + { + // remove everything from the backslash (included) + line = line.substr(0, line.size() - (last - line.rbegin()) - 1); + + std::string next_line; + if(!getline(is, next_line)) + break; + + line += next_line; + last = std::find_if(line.rbegin(), line.rend(), [](char c) { return c != '\0' && !std::isspace(c); }); + } + + CGAL_assertion(!line.empty()); std::istringstream iss(line); if(!(iss >> s)) - continue; // can't read anything on the line, whitespace only? + continue; if(s == "v") {