- Bugfix : Bug 3511751 closed, handling no defined material name.

- Update : Add a model for the regression test.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1244 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
This commit is contained in:
kimmi
2012-05-01 09:39:51 +00:00
parent 425c929aaa
commit f9cd8845b1
4 changed files with 547 additions and 13 deletions

View File

@@ -219,22 +219,29 @@ void ObjFileMtlImporter::getFloatValue( float &value )
// Creates a material from loaded data.
void ObjFileMtlImporter::createMaterial()
{
std::string strName( "" );
m_DataIt = getName<DataArrayIt>( m_DataIt, m_DataItEnd, strName );
if ( m_DataItEnd == m_DataIt )
return;
std::string line( "" );
while ( !isNewLine( *m_DataIt ) ) {
line += *m_DataIt;
++m_DataIt;
}
std::vector<std::string> token;
const unsigned int numToken = tokenize<std::string>( line, token, " " );
std::string name( "" );
if ( numToken == 1 ) {
name = AI_DEFAULT_MATERIAL_NAME;
} else {
name = token[ 1 ];
}
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName );
if ( m_pModel->m_MaterialMap.end() == it)
{
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
if ( m_pModel->m_MaterialMap.end() == it) {
// New Material created
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
m_pModel->m_pCurrentMaterial->MaterialName.Set( strName );
m_pModel->m_MaterialLib.push_back( strName );
m_pModel->m_MaterialMap[ strName ] = m_pModel->m_pCurrentMaterial;
}
else
{
m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
m_pModel->m_MaterialLib.push_back( name );
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
} else {
// Use older material
m_pModel->m_pCurrentMaterial = (*it).second;
}

View File

@@ -222,6 +222,32 @@ inline char_t getFloat( char_t it, char_t end, float &value )
return it;
}
template<class string_type>
unsigned int tokenize( const string_type& str, std::vector<string_type>& tokens,
const string_type& delimiters )
{
// Skip delimiters at beginning.
string_type::size_type lastPos = str.find_first_not_of( delimiters, 0 );
// Find first "non-delimiter".
string_type::size_type pos = str.find_first_of( delimiters, lastPos );
while ( string_type::npos != pos || string_type::npos != lastPos )
{
// Found a token, add it to the vector.
string_type tmp = str.substr(lastPos, pos - lastPos);
if ( !tmp.empty() && ' ' != tmp[ 0 ] )
tokens.push_back( tmp );
// Skip delimiters. Note the "not_of"
lastPos = str.find_first_not_of( delimiters, pos );
// Find next "non-delimiter"
pos = str.find_first_of( delimiters, lastPos );
}
return static_cast<unsigned int>( tokens.size() );
}
} // Namespace Assimp
#endif