From 54c28bd05f8de8876d05ab930d4df5f1a3f7bac4 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 15 May 2016 19:18:21 +0900 Subject: [PATCH] Fix vertex_index creation. --- experimental/optimized-parse.cc | 38 ++++++++++++++++++--------------- experimental/premake4.lua | 10 ++++----- experimental/viewer.cc | 3 +++ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/experimental/optimized-parse.cc b/experimental/optimized-parse.cc index 6894184..ef6b4fb 100644 --- a/experimental/optimized-parse.cc +++ b/experimental/optimized-parse.cc @@ -1,3 +1,7 @@ +// +//@todo { parse material. assign material id } +//@todo { support object&group } +// #ifdef _WIN64 #define atoll(S) _atoi64(S) #include @@ -943,15 +947,15 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration ms = end_time - start_time; - std::cout << "line detection:" << ms.count() << " ms\n"; + //std::cout << "line detection:" << ms.count() << " ms\n"; } auto line_sum = 0; for (size_t t = 0; t < num_threads; t++) { - std::cout << t << ": # of lines = " << line_infos[t].size() << std::endl; + //std::cout << t << ": # of lines = " << line_infos[t].size() << std::endl; line_sum += line_infos[t].size(); } - std::cout << "# of lines = " << line_sum << std::endl; + //std::cout << "# of lines = " << line_sum << std::endl; std::vector commands[kMaxThreads]; @@ -962,7 +966,7 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto auto t2 = std::chrono::high_resolution_clock::now(); std::chrono::duration ms1 = t2 - t1; - std::cout << ms1.count() << " ms\n"; + //std::cout << ms1.count() << " ms\n"; CommandCount command_count[kMaxThreads]; @@ -1001,7 +1005,7 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto auto t_end = std::chrono::high_resolution_clock::now(); std::chrono::duration ms = t_end - t_start; - std::cout << "parse:" << ms.count() << " ms\n"; + //std::cout << "parse:" << ms.count() << " ms\n"; } auto command_sum = 0; @@ -1021,10 +1025,10 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto num_vt += command_count[t].num_vt; num_f += command_count[t].num_f; } - std::cout << "# v " << num_v << std::endl; - std::cout << "# vn " << num_vn << std::endl; - std::cout << "# vt " << num_vt << std::endl; - std::cout << "# f " << num_f << std::endl; + //std::cout << "# v " << num_v << std::endl; + //std::cout << "# vn " << num_vn << std::endl; + //std::cout << "# vt " << num_vt << std::endl; + //std::cout << "# f " << num_f << std::endl; vertices.reserve(num_v * 3); normals.reserve(num_vn * 3); @@ -1067,15 +1071,15 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto int v_idx = fixIndex(i0.v_idx, v_size); int vn_idx = fixIndex(i0.vn_idx, vn_size); int vt_idx = fixIndex(i0.vt_idx, vt_size); - faces.emplace_back(vertex_index(v_idx, vn_idx, vt_idx)); + faces.emplace_back(vertex_index(v_idx, vt_idx, vn_idx)); v_idx = fixIndex(i1.v_idx, v_size); vn_idx = fixIndex(i1.vn_idx, vn_size); vt_idx = fixIndex(i1.vt_idx, vt_size); - faces.emplace_back(vertex_index(v_idx, vn_idx, vt_idx)); + faces.emplace_back(vertex_index(v_idx, vt_idx, vn_idx)); v_idx = fixIndex(i2.v_idx, v_size); vn_idx = fixIndex(i2.vn_idx, vn_size); vt_idx = fixIndex(i2.vt_idx, vt_size); - faces.emplace_back(vertex_index(v_idx, vn_idx, vt_idx)); + faces.emplace_back(vertex_index(v_idx, vt_idx, vn_idx)); } } } @@ -1084,18 +1088,18 @@ void parse(std::vector &vertices, std::vector &normals, std::vecto auto t_end = std::chrono::high_resolution_clock::now(); std::chrono::duration ms = t_end - t_start; - std::cout << "merge:" << ms.count() << " ms\n"; + //std::cout << "merge:" << ms.count() << " ms\n"; } + auto t4 = std::chrono::high_resolution_clock::now(); + + std::chrono::duration ms_total = t4 - t1; + std::cout << "total parsing time: " << ms_total.count() << " ms\n"; std::cout << "# of vertices = " << vertices.size() << std::endl; std::cout << "# of normals = " << normals.size() << std::endl; std::cout << "# of texcoords = " << texcoords.size() << std::endl; std::cout << "# of faces = " << faces.size() << std::endl; - auto t4 = std::chrono::high_resolution_clock::now(); - - std::chrono::duration ms_total = t4 - t1; - std::cout << "total: " << ms_total.count() << " ms\n"; } diff --git a/experimental/premake4.lua b/experimental/premake4.lua index e302e91..6df8335 100644 --- a/experimental/premake4.lua +++ b/experimental/premake4.lua @@ -1,6 +1,6 @@ solution "objview" -- location ( "build" ) - configurations { "Debug", "Release" } + configurations { "Release", "Debug" } platforms {"native", "x64", "x32"} project "objview" @@ -12,8 +12,8 @@ solution "objview" includedirs { "../../" } buildoptions { "-std=c++11" } - buildoptions { "-fsanitize=address" } - linkoptions { "-fsanitize=address" } + --buildoptions { "-fsanitize=address" } + --linkoptions { "-fsanitize=address" } configuration { "linux" } linkoptions { "`pkg-config --libs glfw3`" } @@ -40,9 +40,9 @@ solution "objview" configuration "Debug" defines { "DEBUG" } - flags { "Symbols", "ExtraWarnings"} + flags { "Symbols"} configuration "Release" defines { "NDEBUG" } - flags { "Optimize", "ExtraWarnings"} + flags { "Optimize"} diff --git a/experimental/viewer.cc b/experimental/viewer.cc index 2691fcb..1990342 100644 --- a/experimental/viewer.cc +++ b/experimental/viewer.cc @@ -194,6 +194,9 @@ bool LoadObjAndConvert(float bmin[3], float bmax[3], const char* filename) assert(f0 >= 0); assert(f1 >= 0); assert(f2 >= 0); + assert(3*f0+2 < normals.size()); + assert(3*f1+2 < normals.size()); + assert(3*f2+2 < normals.size()); for (int k = 0; k < 3; k++) { n[0][k] = normals[3*f0+k]; n[1][k] = normals[3*f1+k];