diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index 5b5160a44..6653b30ce 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -284,6 +284,8 @@ void ObjFileMtlImporter::createMaterial() } } + name = trim_whitespaces(name); + std::map::iterator it = m_pModel->m_MaterialMap.find( name ); if ( m_pModel->m_MaterialMap.end() == it) { // New Material created diff --git a/code/ObjFileParser.cpp b/code/ObjFileParser.cpp index cc898f2a0..5428bdad2 100644 --- a/code/ObjFileParser.cpp +++ b/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; diff --git a/code/ObjTools.h b/code/ObjTools.h index b5ed12192..04e2b042d 100644 --- a/code/ObjTools.h +++ b/code/ObjTools.h @@ -238,6 +238,14 @@ unsigned int tokenize( const string_type& str, std::vector& tokens, return static_cast( tokens.size() ); } +template +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