Skip to content
Permalink
Browse files

Fixed workaround for invalid indices

  • Loading branch information
robertosfield committed Jan 14, 2020
1 parent 5940ac3 commit 0405469bf08bd01b6675b7cafa1b4987461165c5
Showing with 4 additions and 10 deletions.
  1. +4 −10 src/osgPlugins/obj/obj.cpp
@@ -668,28 +668,22 @@ bool Model::readOBJ(std::istream& fin, const osgDB::ReaderWriter::Options* optio

if (sscanf(ptr, "%d/%d/%d", &vi, &ti, &ni) == 3)
{
// OSG_NOTICE<<" vi="<<vi<<"/ti="<<ti<<"/ni="<<ni<<std::endl;
element->vertexIndices.push_back(remapVertexIndex(vi));
element->normalIndices.push_back(remapNormalIndex(ni));
element->texCoordIndices.push_back(remapTexCoordIndex(ti));
if (normals.size() > 0 && remapNormalIndex(ni) < static_cast<int>(normals.size())) element->normalIndices.push_back(remapNormalIndex(ni));
if (texcoords.size() > 0 && remapTexCoordIndex(ti) < static_cast<int>(texcoords.size())) element->texCoordIndices.push_back(remapTexCoordIndex(ti));
}
else if (sscanf(ptr, "%d//%d", &vi, &ni) == 2)
{
// OSG_NOTICE<<" vi="<<vi<<"//ni="<<ni<<std::endl;
element->vertexIndices.push_back(remapVertexIndex(vi));
if (remapNormalIndex(ni) < static_cast<int>(normals.size()))
element->normalIndices.push_back(remapNormalIndex(ni));
if (normals.size() > 0 && remapNormalIndex(ni) < static_cast<int>(normals.size())) element->normalIndices.push_back(remapNormalIndex(ni));
}
else if (sscanf(ptr, "%d/%d", &vi, &ti) == 2)
{
// OSG_NOTICE<<" vi="<<vi<<"/ti="<<ti<<std::endl;
element->vertexIndices.push_back(remapVertexIndex(vi));
if (remapTexCoordIndex(ti) < static_cast<int>(texcoords.size()))
element->texCoordIndices.push_back(remapTexCoordIndex(ti));
if (texcoords.size() > 0 && remapTexCoordIndex(ti) < static_cast<int>(texcoords.size())) element->texCoordIndices.push_back(remapTexCoordIndex(ti));
}
else if (sscanf(ptr, "%d", &vi) == 1)
{
// OSG_NOTICE<<" vi="<<vi<<std::endl;
element->vertexIndices.push_back(remapVertexIndex(vi));
}

0 comments on commit 0405469

Please sign in to comment.
You can’t perform that action at this time.