Adds support for incomplete stl binary files

The logic is
* if a file is not ascii
* if its sizeis less than the expected binary size
then we can assume that the data is incomplete but still try to load it.
This commit is contained in:
Marc Helbling
2016-07-05 17:08:08 +02:00
parent f4d0131967
commit e4c31cdcbf

View File

@@ -481,8 +481,16 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil
std::string header_text(header.text, sizeof(header.text));
if (stb.st_size == expectLen)
if (header_text.find("solid") == std::string::npos || stb.st_size == expectLen)
{
if(stb.st_size < expectLen)
{
unsigned int facets = (stb.st_size - sizeof_StlHeader) / sizeof_StlFacet;
OSG_WARN << "Warning: [[stl]] Incomplete file. "
<< "Attempting to read " << facets << " out of " << expectFacets << " facets expected."
<< std::endl;
expectFacets = facets;
}
isBinary = true;
}
else if (header_text.find("solid") != std::string::npos)