Browse Source

Merge branch 'master' into bug/keep_small_triangles_in_triangulation

Kim Kulling 7 years ago
parent
commit
1a0231f91e
3 changed files with 10 additions and 3 deletions
  1. 7 1
      code/BaseImporter.cpp
  2. 1 1
      code/ObjFileImporter.cpp
  3. 2 1
      include/assimp/BaseImporter.h

+ 7 - 1
code/BaseImporter.cpp

@@ -143,7 +143,8 @@ void BaseImporter::GetExtensionList(std::set<std::string>& extensions) {
     const char**        tokens,
     const char**        tokens,
     unsigned int        numTokens,
     unsigned int        numTokens,
     unsigned int        searchBytes /* = 200 */,
     unsigned int        searchBytes /* = 200 */,
-    bool                tokensSol /* false */)
+    bool                tokensSol /* false */,
+    bool                noAlphaBeforeTokens /* false */)
 {
 {
     ai_assert( nullptr != tokens );
     ai_assert( nullptr != tokens );
     ai_assert( 0 != numTokens );
     ai_assert( 0 != numTokens );
@@ -193,6 +194,11 @@ void BaseImporter::GetExtensionList(std::set<std::string>& extensions) {
             if( !r ) {
             if( !r ) {
                 continue;
                 continue;
             }
             }
+            // We need to make sure that we didn't accidentially identify the end of another token as our token,
+            // e.g. in a previous version the "gltf " present in some gltf files was detected as "f "
+            if (noAlphaBeforeTokens && (r != buffer && isalpha(r[-1]))) {
+                continue;
+            }
             // We got a match, either we don't care where it is, or it happens to
             // We got a match, either we don't care where it is, or it happens to
             // be in the beginning of the file / line
             // be in the beginning of the file / line
             if (!tokensSol || r == buffer || r[-1] == '\r' || r[-1] == '\n') {
             if (!tokensSol || r == buffer || r[-1] == '\r' || r[-1] == '\n') {

+ 1 - 1
code/ObjFileImporter.cpp

@@ -100,7 +100,7 @@ bool ObjFileImporter::CanRead( const std::string& pFile, IOSystem*  pIOHandler ,
     } else {
     } else {
         // Check file Header
         // Check file Header
         static const char *pTokens[] = { "mtllib", "usemtl", "v ", "vt ", "vn ", "o ", "g ", "s ", "f " };
         static const char *pTokens[] = { "mtllib", "usemtl", "v ", "vt ", "vn ", "o ", "g ", "s ", "f " };
-        return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 9 );
+        return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 9, 200, false, true );
     }
     }
 }
 }
 
 

+ 2 - 1
include/assimp/BaseImporter.h

@@ -244,7 +244,8 @@ public: // static utilities
         const char** tokens,
         const char** tokens,
         unsigned int numTokens,
         unsigned int numTokens,
         unsigned int searchBytes = 200,
         unsigned int searchBytes = 200,
-        bool tokensSol = false);
+        bool tokensSol = false,
+        bool noAlphaBeforeTokens = false);
 
 
     // -------------------------------------------------------------------
     // -------------------------------------------------------------------
     /** @brief Check whether a file has a specific file extension
     /** @brief Check whether a file has a specific file extension