ソースを参照

trimming spaces around material names

Vitaly Ovchinnikov 9 年 前
コミット
af40c99a6a
3 ファイル変更11 行追加0 行削除
  1. 2 0
      code/ObjFileMtlImporter.cpp
  2. 1 0
      code/ObjFileParser.cpp
  3. 8 0
      code/ObjTools.h

+ 2 - 0
code/ObjFileMtlImporter.cpp

@@ -284,6 +284,8 @@ void ObjFileMtlImporter::createMaterial()
         }
     }
 
+    name = trim_whitespaces(name);
+
     std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
     if ( m_pModel->m_MaterialMap.end() == it) {
         // New Material created

+ 1 - 0
code/ObjFileParser.cpp

@@ -473,6 +473,7 @@ void ObjFileParser::getMaterialDesc()
 
     // Get name
     std::string strName(pStart, &(*m_DataIt));
+    strName = trim_whitespaces(strName);
     if (strName.empty())
         skip = true;
 

+ 8 - 0
code/ObjTools.h

@@ -238,6 +238,14 @@ unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
     return static_cast<unsigned int>( tokens.size() );
 }
 
+template <class string_type>
+string_type trim_whitespaces(string_type str)
+{
+    while (!str.empty() && IsSpace(str[0])) str.erase(0);
+    while (!str.empty() && IsSpace(str[str.length() - 1])) str.erase(str.length() - 1);
+    return str;
+}
+
 } // Namespace Assimp
 
 #endif // OBJ_TOOLS_H_INC