From e72ed3b27440d96617820eb70479962b05b5f25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Wed, 13 May 2009 06:05:43 +0000 Subject: [PATCH] Fixed obj reader for negative texture index and normals git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@126 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/IO/reader/OBJReader.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/OpenMesh/Core/IO/reader/OBJReader.cc b/src/OpenMesh/Core/IO/reader/OBJReader.cc index 22e47f28..44c1fa19 100644 --- a/src/OpenMesh/Core/IO/reader/OBJReader.cc +++ b/src/OpenMesh/Core/IO/reader/OBJReader.cc @@ -443,19 +443,25 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt) { case 0: // vertex if ( value < 0 ) { -// std::cerr << "Handling negativ vertex index value" << std::endl; + // Calculation of index : + // -1 is the last vertex in the list + // As obj counts from 1 and not zero add +1 value = _bi.n_vertices() + value + 1; } + // Obj counts from 1 and not zero .. array counts from zero therefore -1 vhandles.push_back(VertexHandle(value-1)); break; case 1: // texture coord if ( value < 0 ) { -// std::cerr << "Handling negativ texture coordinate index value)" << std::endl; - value = _bi.n_vertices() + value + 1; + // Calculation of index : + // -1 is the last vertex in the list + // As obj counts from 1 and not zero add +1 + value = texcoords.size() + value + 1; } assert(!vhandles.empty()); if ( ! texcoords.empty() && (unsigned int)(value-1) < texcoords.size() ) { + // Obj counts from 1 and not zero .. array counts from zero therefore -1 _bi.set_texcoord(vhandles.back(), texcoords[value-1]); face_texcoords.push_back( texcoords[value-1] ); } else { @@ -466,11 +472,14 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt) case 2: // normal if ( value < 0 ) { -// std::cerr << "Handling negativ normal index value)" << std::endl; - value = _bi.n_vertices() + value + 1; + // Calculation of index : + // -1 is the last vertex in the list + // As obj counts from 1 and not zero add +1 + value = normals.size() + value + 1; } assert(!vhandles.empty()); assert((unsigned int)(value-1) < normals.size()); + // Obj counts from 1 and not zero .. array counts from zero therefore -1 _bi.set_normal(vhandles.back(), normals[value-1]); break; }