diff --git a/experimental/optimized-parse.cc b/experimental/optimized-parse.cc index 4e1a8eb..c5c8d04 100644 --- a/experimental/optimized-parse.cc +++ b/experimental/optimized-parse.cc @@ -623,7 +623,7 @@ struct CommandCount } }; -static bool parseLine(Command *command, const char *p, size_t p_len) +static bool parseLine(Command *command, const char *p, size_t p_len, bool triangulate = true) { char linebuf[4096]; assert(p_len < 4095); @@ -690,6 +690,8 @@ static bool parseLine(Command *command, const char *p, size_t p_len) //token += strspn(token, " \t"); skip_space(&token); + StackVector f; + while (!IS_NEW_LINE(token[0])) { vertex_index vi = parseRawTriple(&token); //printf("v = %d, %d, %d\n", vi.v_idx, vi.vn_idx, vi.vt_idx); @@ -700,11 +702,31 @@ static bool parseLine(Command *command, const char *p, size_t p_len) //token += n; skip_space_and_cr(&token); - command->f.push_back(vi); + f->push_back(vi); } command->type = COMMAND_F; + if (triangulate) { + vertex_index i0 = f[0]; + vertex_index i1(-1); + vertex_index i2 = f[1]; + + for (size_t k = 2; k < f->size(); k++) { + i1 = i2; + i2 = f[k]; + command->f.emplace_back(i0); + command->f.emplace_back(i1); + command->f.emplace_back(i2); + } + + } else { + + for (size_t k = 0; k < f->size(); k++) { + command->f.emplace_back(f[k]); + } + } + return true; } @@ -965,8 +987,8 @@ bool parse(std::vector> &vertices, std::vector