Merge branch 'OBJ-loader-negative-indices' into 'master'
Fix for handling negative indices in OBJ loader This fix resolves an issue that occurrs with the current code that uses two passes to parse the OBJ - see my previous merge request: https://graphics.rwth-aachen.de:9000/OpenMesh/OpenMesh/merge_requests/84 Sorry for the trouble! :-( To verify that the negative indices were really not working any more, and to check that this fix resolves the issue, I used the Cornell Box example from the tiny OBJ loader project: https://github.com/syoyo/tinyobjloader/blob/master/models/cornell_box.obj See merge request !93
This commit is contained in:
@@ -443,6 +443,10 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
_in.clear();
|
_in.clear();
|
||||||
_in.seekg(0, std::ios::beg);
|
_in.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
|
int nCurrentPositions = 0,
|
||||||
|
nCurrentTexcoords = 0,
|
||||||
|
nCurrentNormals = 0;
|
||||||
|
|
||||||
// pass 2: read faces
|
// pass 2: read faces
|
||||||
while( _in && !_in.eof() )
|
while( _in && !_in.eof() )
|
||||||
{
|
{
|
||||||
@@ -513,6 +517,21 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// track current number of parsed vertex attributes,
|
||||||
|
// to allow for OBJs negative indices
|
||||||
|
else if (keyWrd == "v")
|
||||||
|
{
|
||||||
|
++nCurrentPositions;
|
||||||
|
}
|
||||||
|
else if (keyWrd == "vt")
|
||||||
|
{
|
||||||
|
++nCurrentTexcoords;
|
||||||
|
}
|
||||||
|
else if (keyWrd == "vn")
|
||||||
|
{
|
||||||
|
++nCurrentNormals;
|
||||||
|
}
|
||||||
|
|
||||||
// faces
|
// faces
|
||||||
else if (keyWrd == "f")
|
else if (keyWrd == "f")
|
||||||
{
|
{
|
||||||
@@ -592,7 +611,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
// Calculation of index :
|
// Calculation of index :
|
||||||
// -1 is the last vertex in the list
|
// -1 is the last vertex in the list
|
||||||
// As obj counts from 1 and not zero add +1
|
// As obj counts from 1 and not zero add +1
|
||||||
value = int(_bi.n_vertices() + value + 1);
|
value = nCurrentPositions + value + 1;
|
||||||
}
|
}
|
||||||
// Obj counts from 1 and not zero .. array counts from zero therefore -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));
|
||||||
@@ -612,7 +631,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
// Calculation of index :
|
// Calculation of index :
|
||||||
// -1 is the last vertex in the list
|
// -1 is the last vertex in the list
|
||||||
// As obj counts from 1 and not zero add +1
|
// As obj counts from 1 and not zero add +1
|
||||||
value = int(texcoords.size()) + value + 1;
|
value = nCurrentTexcoords + value + 1;
|
||||||
}
|
}
|
||||||
assert(!vhandles.empty());
|
assert(!vhandles.empty());
|
||||||
|
|
||||||
@@ -649,7 +668,7 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
|
|||||||
// Calculation of index :
|
// Calculation of index :
|
||||||
// -1 is the last vertex in the list
|
// -1 is the last vertex in the list
|
||||||
// As obj counts from 1 and not zero add +1
|
// As obj counts from 1 and not zero add +1
|
||||||
value = int(normals.size()) + value + 1;
|
value = nCurrentNormals + value + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obj counts from 1 and not zero .. array counts from zero therefore -1
|
// Obj counts from 1 and not zero .. array counts from zero therefore -1
|
||||||
|
|||||||
Reference in New Issue
Block a user