Kim Kulling 2015-08-08 10:55:10 +02:00
parent 88746af2e6
commit e794aaf017
1 changed files with 22 additions and 7 deletions

View File

@ -75,8 +75,9 @@ static const aiImporterDesc desc = {
// 2) 4 byte face count
// 3) 50 bytes per face
bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
if (fileSize < 84)
if( fileSize < 84 ) {
return false;
}
const uint32_t faceCount = *reinterpret_cast<const uint32_t*>(buffer + 80);
const uint32_t expectedBinaryFileSize = faceCount * 50 + 84;
@ -99,7 +100,20 @@ bool IsAsciiSTL(const char* buffer, unsigned int fileSize) {
if (buffer + 5 >= bufferEnd)
return false;
return strncmp(buffer, "solid", 5) == 0;
bool isASCII( strncmp( buffer, "solid", 5 ) == 0 );
if( isASCII ) {
// A lot of importers are write solit even if the file is binary. So we have to check for ascii characters.
if( fileSize >= 500 ) {
isASCII = true;
for( unsigned int i = 0; i < 500; i++ ) {
if( buffer[ i ] > 127 ) {
isASCII = false;
break;
}
}
}
}
return isASCII;
}
} // namespace
@ -122,20 +136,21 @@ bool STLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool
{
const std::string extension = GetExtension(pFile);
if (extension == "stl")
if( extension == "stl" ) {
return true;
else if (!extension.length() || checkSig) {
if (!pIOHandler)
} else if (!extension.length() || checkSig) {
if( !pIOHandler ) {
return true;
}
const char* tokens[] = {"STL","solid"};
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,2);
}
return false;
}
// ------------------------------------------------------------------------------------------------
const aiImporterDesc* STLImporter::GetInfo () const
{
const aiImporterDesc* STLImporter::GetInfo () const {
return &desc;
}