From 7c472b4ca55889c6285bb1eb6f6d9a4aeebf85c5 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 23 Mar 2015 01:54:52 +0100 Subject: [PATCH 1/2] Geometryc now properly handles relative obj indices. --- tools/geometryc/geometryc.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index 23ecb1088..c2ee40398 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -507,8 +507,8 @@ int main(int _argc, const char* _argv[]) for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge) { Index3 index; - index.m_texcoord = -1; - index.m_normal = -1; + index.m_texcoord = 0; + index.m_normal = 0; index.m_vertexIndex = -1; char* vertex = argv[edge+1]; @@ -521,13 +521,16 @@ int main(int _argc, const char* _argv[]) if (NULL != normal) { *normal++ = '\0'; - index.m_normal = atoi(normal)-1; + const int nn = atoi(normal); + index.m_normal = (nn < 0) ? nn+(int)normals.size() : nn-1; } - index.m_texcoord = atoi(texcoord)-1; + const int tex = atoi(texcoord); + index.m_texcoord = (tex < 0) ? tex+(int)texcoords.size() : tex-1; } - index.m_position = atoi(vertex)-1; + const int pos = atoi(vertex); + index.m_position = (pos < 0) ? pos+(int)positions.size() : pos-1; uint64_t hash0 = index.m_position; uint64_t hash1 = uint64_t(index.m_texcoord)<<20; @@ -710,8 +713,8 @@ int main(int _argc, const char* _argv[]) bool hasTexcoord; { Index3Map::const_iterator it = indexMap.begin(); - hasNormal = -1 != it->second.m_normal; - hasTexcoord = -1 != it->second.m_texcoord; + hasNormal = 0 != it->second.m_normal; + hasTexcoord = 0 != it->second.m_texcoord; if (!hasTexcoord && texcoords.size() == positions.size() ) From 720efbbdb0fdbb647e8be25feee59aba97099551 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Mon, 23 Mar 2015 02:00:41 +0100 Subject: [PATCH 2/2] Cleanup. --- tools/geometryc/geometryc.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index c2ee40398..f748e5c79 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -504,6 +504,9 @@ int main(int _argc, const char* _argv[]) Triangle triangle; memset(&triangle, 0, sizeof(Triangle) ); + const int numNormals = (int)normals.size(); + const int numTexcoords = (int)texcoords.size(); + const int numPositions = (int)positions.size(); for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge) { Index3 index; @@ -522,15 +525,15 @@ int main(int _argc, const char* _argv[]) { *normal++ = '\0'; const int nn = atoi(normal); - index.m_normal = (nn < 0) ? nn+(int)normals.size() : nn-1; + index.m_normal = (nn < 0) ? nn+numNormals : nn-1; } const int tex = atoi(texcoord); - index.m_texcoord = (tex < 0) ? tex+(int)texcoords.size() : tex-1; + index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1; } const int pos = atoi(vertex); - index.m_position = (pos < 0) ? pos+(int)positions.size() : pos-1; + index.m_position = (pos < 0) ? pos+numPositions : pos-1; uint64_t hash0 = index.m_position; uint64_t hash1 = uint64_t(index.m_texcoord)<<20;