From 4df0cca212a3ab243c0422f88e0a103da88cfa85 Mon Sep 17 00:00:00 2001 From: Nodrev Date: Tue, 2 Jun 2015 22:37:22 +0200 Subject: [PATCH] Fixing geometryc for meshes exported without uv coordinates --- tools/geometryc/geometryc.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/geometryc/geometryc.cpp b/tools/geometryc/geometryc.cpp index ccf6a580..d55d4a2e 100644 --- a/tools/geometryc/geometryc.cpp +++ b/tools/geometryc/geometryc.cpp @@ -510,8 +510,8 @@ int main(int _argc, const char* _argv[]) for (uint32_t edge = 0, numEdges = argc-1; edge < numEdges; ++edge) { Index3 index; - index.m_texcoord = 0; - index.m_normal = 0; + index.m_texcoord = -1; + index.m_normal = -1; index.m_vertexIndex = -1; char* vertex = argv[edge+1]; @@ -528,8 +528,12 @@ int main(int _argc, const char* _argv[]) index.m_normal = (nn < 0) ? nn+numNormals : nn-1; } - const int tex = atoi(texcoord); - index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1; + // https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_Normal_Indices_Without_Texture_Coordinate_Indices + if(*texcoord != '\0') + { + const int tex = atoi(texcoord); + index.m_texcoord = (tex < 0) ? tex+numTexcoords : tex-1; + } } const int pos = atoi(vertex); @@ -716,8 +720,8 @@ int main(int _argc, const char* _argv[]) bool hasTexcoord; { Index3Map::const_iterator it = indexMap.begin(); - hasNormal = 0 != it->second.m_normal; - hasTexcoord = 0 != it->second.m_texcoord; + hasNormal = -1 != it->second.m_normal; + hasTexcoord = -1 != it->second.m_texcoord; if (!hasTexcoord && texcoords.size() == positions.size() )