OBJ: Support spaces in material names, fixes #545.

Adding test file.
pull/554/head
Alexander Gessler 2015-05-10 23:50:18 +02:00 committed by Alexander Gessler
parent 67fb135ce8
commit faea2ecccc
4 changed files with 105 additions and 10 deletions

View File

@ -263,16 +263,21 @@ void ObjFileMtlImporter::createMaterial()
}
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 ];
}
const unsigned int numToken = tokenize<std::string>( line, token, " \t" );
std::string name( "" );
if ( numToken == 1 ) {
name = AI_DEFAULT_MATERIAL_NAME;
} else {
// skip newmtl and all following white spaces
std::size_t first_ws_pos = line.find_first_of(" \t");
std::size_t first_non_ws_pos = line.find_first_not_of(" \t", first_ws_pos);
if (first_non_ws_pos != std::string::npos) {
name = line.substr(first_non_ws_pos);
}
}
std::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( name );
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( name );

View File

@ -469,7 +469,7 @@ void ObjFileParser::getMaterialDesc()
return;
char *pStart = &(*m_DataIt);
while( m_DataIt != m_DataItEnd && !IsSpaceOrNewLine( *m_DataIt ) ) {
while( m_DataIt != m_DataItEnd && !IsLineEnd( *m_DataIt ) ) {
++m_DataIt;
}

View File

@ -0,0 +1,13 @@
# Example for github issue #545: spaces in material names.
newmtl Hard Shiny Plastic White
Ka 0 0 0
Kd 0.141176 0.184314 0.411765
Ks 0 0 0
Ni 1
Ns 400
Tf 1 1 1
d 1

View File

@ -0,0 +1,77 @@
####
#
# OBJ File Generated by LightWave3D
# LightWave3D OBJ Export v2.3
#
####
o concave_test.obj
mtllib space_in_material_name.mtl
g default
v -1.146 1.6575 2.348
v -1.146 1.67177 2.49285
v -1.146 1.67177 2.20315
v -1.146 1.7125 2.35
v -1.146 1.71402 2.63214
v -1.146 1.71402 2.06386
v -1.146 1.72571 2.48412
v -1.146 1.72571 2.21588
v -1.146 1.76483 2.61309
v -1.146 1.76483 2.08691
v -1.146 1.78263 2.76051
v -1.146 1.78263 1.93549
v -1.146 1.82836 2.73195
v -1.146 1.82836 1.96805
v -1.146 1.87497 2.87303
v -1.146 1.87497 1.82297
v -1.146 1.91386 2.83614
v -1.146 1.91386 1.86386
v -1.146 1.98749 2.96537
v -1.146 1.98749 1.73063
v -1.146 2.01805 2.92164
v -1.146 2.01805 1.77836
v -1.146 2.11586 3.03398
v -1.146 2.11586 1.66202
v -1.146 2.13691 2.98517
v -1.146 2.13691 1.71483
v -1.146 2.25515 3.07623
v -1.146 2.25515 1.61977
v -1.146 2.26588 3.02429
v -1.146 2.26588 1.67571
v -1.146 2.4 3.0905
v -1.146 2.4 3.0375
v -1.146 2.4 1.6625
v -1.146 2.4 1.6055
v -1.146 2.53412 3.02429
v -1.146 2.53412 1.67571
v -1.146 2.54485 3.07623
v -1.146 2.54485 1.61977
v -1.146 2.66309 2.98517
v -1.146 2.66309 1.71483
v -1.146 2.68414 3.03398
v -1.146 2.68414 1.66202
v -1.146 2.78195 2.92164
v -1.146 2.78195 1.77836
v -1.146 2.81251 2.96537
v -1.146 2.81251 1.73063
v -1.146 2.88614 2.83614
v -1.146 2.88614 1.86386
v -1.146 2.92503 2.87303
v -1.146 2.92503 1.82297
v -1.146 2.97164 2.73195
v -1.146 2.97164 1.96805
v -1.146 3.01737 2.76051
v -1.146 3.01737 1.93549
v -1.146 3.03517 2.61309
v -1.146 3.03517 2.08691
v -1.146 3.07429 2.48412
v -1.146 3.07429 2.21588
v -1.146 3.08598 2.63214
v -1.146 3.08598 2.06386
v -1.146 3.0875 2.35
v -1.146 3.12823 2.49285
v -1.146 3.12823 2.20315
v -1.146 3.1425 2.348
vn 1 0 -0
usemtl Hard Shiny Plastic White
s 1
f 27//1 23//1 19//1 15//1 11//1 5//1 2//1 1//1 3//1 6//1 12//1 16//1 20//1 24//1 28//1 34//1 38//1 42//1 46//1 50//1 54//1 60//1 63//1 64//1 62//1 59//1 53//1 49//1 45//1 41//1 37//1 31//1 32//1 35//1 39//1 43//1 47//1 51//1 55//1 57//1 61//1 58//1 56//1 52//1 48//1 44//1 40//1 36//1 33//1 30//1 26//1 22//1 18//1 14//1 10//1 8//1 4//1 7//1 9//1 13//1 17//1 21//1 25//1 29//1 32//1 31//1