Fix T97863: new OBJ importer issues with extra whitespace after "f" keywords

While possible extra whitespace after all OBJ/MTL keywords was properly
skipped, it was not done for the "f" (face definition) keyword.

While at it, also support indented keywords, i.e. extra whitespace at
the beginning of the line.

There's a tiny bit of performance drop while importing (e.g. importing
blender 3.0 splash scene: 53.38sec -> 54.21sec on my machine). But
correctness is more important.

Reviewed By: Howard Trickey
Differential Revision: https://developer.blender.org/D14854
This commit is contained in:
Aras Pranckevicius 2022-05-05 14:57:40 +03:00
parent 756710800c
commit 1830a3dfb5

View File

@ -128,6 +128,7 @@ static void geom_add_polygon(Geometry *geom,
curr_face.start_index_ = orig_corners_size;
bool face_valid = true;
line = drop_whitespace(line);
while (!line.is_empty() && face_valid) {
PolyCorner corner;
bool got_uv = false, got_normal = false;
@ -399,6 +400,7 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
StringRef buffer_str{buffer.data(), (int64_t)last_nl};
while (!buffer_str.is_empty()) {
StringRef line = read_next_line(buffer_str);
line = drop_whitespace(line);
++line_number;
if (line.is_empty()) {
continue;
@ -484,9 +486,6 @@ void OBJParser::parse(Vector<std::unique_ptr<Geometry>> &r_all_geometries,
else if (line.startswith("end")) {
/* End of curve definition, nothing else to do. */
}
else if (line.front() <= ' ') {
/* Just whitespace, skip. */
}
else {
std::cout << "OBJ element not recognized: '" << line << "'" << std::endl;
}