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
This commit is contained in:
@@ -443,19 +443,25 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
{
|
{
|
||||||
case 0: // vertex
|
case 0: // vertex
|
||||||
if ( value < 0 ) {
|
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;
|
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));
|
vhandles.push_back(VertexHandle(value-1));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: // texture coord
|
case 1: // texture coord
|
||||||
if ( value < 0 ) {
|
if ( value < 0 ) {
|
||||||
// std::cerr << "Handling negativ texture coordinate index value)" << std::endl;
|
// Calculation of index :
|
||||||
value = _bi.n_vertices() + value + 1;
|
// -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());
|
assert(!vhandles.empty());
|
||||||
if ( ! texcoords.empty() && (unsigned int)(value-1) < texcoords.size() ) {
|
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]);
|
_bi.set_texcoord(vhandles.back(), texcoords[value-1]);
|
||||||
face_texcoords.push_back( texcoords[value-1] );
|
face_texcoords.push_back( texcoords[value-1] );
|
||||||
} else {
|
} else {
|
||||||
@@ -466,11 +472,14 @@ read(std::fstream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
|
|
||||||
case 2: // normal
|
case 2: // normal
|
||||||
if ( value < 0 ) {
|
if ( value < 0 ) {
|
||||||
// std::cerr << "Handling negativ normal index value)" << std::endl;
|
// Calculation of index :
|
||||||
value = _bi.n_vertices() + value + 1;
|
// -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(!vhandles.empty());
|
||||||
assert((unsigned int)(value-1) < normals.size());
|
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]);
|
_bi.set_normal(vhandles.back(), normals[value-1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user