diff --git a/experimental/tinyobj_loader_opt.h b/experimental/tinyobj_loader_opt.h index 680514d..db9319e 100644 --- a/experimental/tinyobj_loader_opt.h +++ b/experimental/tinyobj_loader_opt.h @@ -951,14 +951,12 @@ bool parseObj(attrib_t *attrib, std::vector *shapes, const char *buf, static bool parseLine(Command *command, const char *p, size_t p_len, bool triangulate = true) { - char linebuf[4096]; - assert(p_len < 4095); - // StackVector linebuf; - // linebuf->resize(p_len + 1); - memcpy(&linebuf, p, p_len); - linebuf[p_len] = '\0'; + //char linebuf[4096]; + //assert(p_len < 4095); + //memcpy(linebuf, p, p_len); + //linebuf[p_len] = '\0'; - const char *token = linebuf; + const char *token = p; command->type = COMMAND_EMPTY; @@ -1078,9 +1076,10 @@ static bool parseLine(Command *command, const char *p, size_t p_len, // namebuf + strlen(namebuf)); // command->material_name->push_back('\0'); skip_space(&token); - command->material_name = p + (token - linebuf); + command->material_name = token; // p + (token - linebuf); command->material_name_len = - length_until_newline(token, p_len - (token - linebuf)) + 1; + length_until_newline(token, p_len - (token - p)) + 1; + //length_until_newline(token, p_len - (token - linebuf)) + 1; command->type = COMMAND_USEMTL; return true; @@ -1092,9 +1091,9 @@ static bool parseLine(Command *command, const char *p, size_t p_len, token += 7; skip_space(&token); - command->mtllib_name = p + (token - linebuf); + command->mtllib_name = token; //p + (token - linebuf); command->mtllib_name_len = - length_until_newline(token, p_len - (token - linebuf)) + 1; + length_until_newline(token, p_len - (token - p)) + 1; command->type = COMMAND_MTLLIB; return true; @@ -1105,9 +1104,9 @@ static bool parseLine(Command *command, const char *p, size_t p_len, // @todo { multiple group name. } token += 2; - command->group_name = p + (token - linebuf); + command->group_name = token; command->group_name_len = - length_until_newline(token, p_len - (token - linebuf)) + 1; + length_until_newline(token, p_len - (token - p)) + 1; command->type = COMMAND_G; return true; @@ -1118,9 +1117,9 @@ static bool parseLine(Command *command, const char *p, size_t p_len, // @todo { multiple object name? } token += 2; - command->object_name = p + (token - linebuf); + command->object_name = token; command->object_name_len = - length_until_newline(token, p_len - (token - linebuf)) + 1; + length_until_newline(token, p_len - (token - p)) + 1; command->type = COMMAND_O; return true; diff --git a/experimental/viewer.cc b/experimental/viewer.cc index 3c32404..d4c9d29 100644 --- a/experimental/viewer.cc +++ b/experimental/viewer.cc @@ -214,9 +214,8 @@ const char* get_file_data(size_t *len, const char* filename) } -bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int num_threads) +bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int num_threads, bool verbose) { -#if 1 tinyobj_opt::attrib_t attrib; std::vector shapes; @@ -229,6 +228,7 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n printf("filesize: %d\n", (int)data_len); tinyobj_opt::LoadOption option; option.req_num_threads = num_threads; + option.verbose = verbose; bool ret = parseObj(&attrib, &shapes, data, data_len, option); bmin[0] = bmin[1] = bmin[2] = std::numeric_limits::max(); @@ -330,9 +330,6 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename, int n printf("bmax = %f, %f, %f\n", bmax[0], bmax[1], bmax[2]); return true; -#else - return false; -#endif } void reshapeFunc(GLFWwindow* window, int w, int h) @@ -499,12 +496,14 @@ static void Init() { int main(int argc, char **argv) { if (argc < 2) { - std::cout << "Needs input.obj\n" << std::endl; + std::cout << "view input.obj " << std::endl; return 0; } bool benchmark_only = false; int num_threads = -1; + bool verbose = false; + if (argc > 2) { num_threads = atoi(argv[2]); } @@ -513,6 +512,10 @@ int main(int argc, char **argv) benchmark_only = true; } + if (argc > 4) { + verbose = true; + } + if (benchmark_only) { tinyobj_opt::attrib_t attrib; @@ -527,6 +530,8 @@ int main(int argc, char **argv) printf("filesize: %d\n", (int)data_len); tinyobj_opt::LoadOption option; option.req_num_threads = num_threads; + option.verbose = true; + bool ret = parseObj(&attrib, &shapes, data, data_len, option); return ret; @@ -569,7 +574,7 @@ int main(int argc, char **argv) reshapeFunc(window, width, height); float bmin[3], bmax[3]; - if (false == LoadObjAndConvert(bmin, bmax, argv[1], num_threads)) { + if (false == LoadObjAndConvert(bmin, bmax, argv[1], num_threads, verbose)) { printf("failed to load & conv\n"); return -1; }