- 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
pull/5/head
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::map<std::string, ObjFile::Material*>::iterator it = m_pModel->m_MaterialMap.find( strName );
if ( m_pModel->m_MaterialMap.end() == it)
{
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( 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

View File

@ -0,0 +1,11 @@
# Blender MTL File: ''
# Material Count: 1
newmtl
Ns 0
Ka 0.000000 0.000000 0.000000
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2

View File

@ -0,0 +1,490 @@
# Blender v2.61 (sub 0) OBJ File: ''
# www.blender.org
mtllib empty_mat.mtl
o Cylinder
v 0.000000 -1.000000 -1.000000
v 0.195090 -1.000000 -0.980785
v 0.382683 -1.000000 -0.923880
v 0.555570 -1.000000 -0.831470
v 0.707107 -1.000000 -0.707107
v 0.831470 -1.000000 -0.555570
v 0.923880 -1.000000 -0.382683
v 0.980785 -1.000000 -0.195090
v 1.000000 -1.000000 -0.000000
v 0.980785 -1.000000 0.195090
v 0.923880 -1.000000 0.382683
v 0.831470 -1.000000 0.555570
v 0.707107 -1.000000 0.707107
v 0.555570 -1.000000 0.831470
v 0.382683 -1.000000 0.923880
v 0.195090 -1.000000 0.980785
v -0.000000 -1.000000 1.000000
v -0.195091 -1.000000 0.980785
v -0.382684 -1.000000 0.923879
v -0.555571 -1.000000 0.831469
v -0.707107 -1.000000 0.707106
v -0.831470 -1.000000 0.555570
v -0.923880 -1.000000 0.382683
v -0.980785 -1.000000 0.195089
v -1.000000 -1.000000 -0.000001
v -0.980785 -1.000000 -0.195091
v -0.923879 -1.000000 -0.382684
v -0.831469 -1.000000 -0.555571
v -0.707106 -1.000000 -0.707108
v -0.555569 -1.000000 -0.831470
v -0.382682 -1.000000 -0.923880
v -0.195089 -1.000000 -0.980786
v 0.000001 1.000000 -0.545415
v 0.106406 1.000000 -0.534934
v 0.208722 1.000000 -0.503897
v 0.303017 1.000000 -0.453495
v 0.385668 1.000000 -0.385665
v 0.453497 1.000000 -0.303015
v 0.503898 1.000000 -0.208720
v 0.534936 1.000000 -0.106403
v 0.545415 1.000000 0.000002
v 0.534935 1.000000 0.106407
v 0.503898 1.000000 0.208723
v 0.453496 1.000000 0.303018
v 0.385667 1.000000 0.385668
v 0.303016 1.000000 0.453497
v 0.208721 1.000000 0.503899
v 0.106405 1.000000 0.534936
v 0.000000 1.000000 0.545416
v -0.106405 1.000000 0.534936
v -0.208721 1.000000 0.503899
v -0.303016 1.000000 0.453498
v -0.385666 1.000000 0.385669
v -0.453496 1.000000 0.303019
v -0.503898 1.000000 0.208724
v -0.534935 1.000000 0.106408
v -0.545416 1.000000 0.000003
v -0.534936 1.000000 -0.106402
v -0.503899 1.000000 -0.208718
v -0.453498 1.000000 -0.303013
v -0.385669 1.000000 -0.385664
v -0.303019 1.000000 -0.453494
v -0.208725 1.000000 -0.503896
v -0.106409 1.000000 -0.534934
v 0.000000 -1.000000 0.000000
v 0.000001 2.006964 -0.545415
v -0.106409 2.006964 -0.534934
v -0.208725 2.006964 -0.503896
v -0.303019 2.006964 -0.453494
v -0.385669 2.006964 -0.385664
v -0.453498 2.006964 -0.303013
v -0.503899 2.006964 -0.208718
v -0.534936 2.006964 -0.106402
v -0.545416 2.006964 0.000003
v -0.534935 2.006964 0.106408
v -0.503898 2.006964 0.208724
v -0.453496 2.006964 0.303019
v -0.385666 2.006964 0.385669
v -0.303016 2.006964 0.453498
v -0.208721 2.006964 0.503899
v -0.106405 2.006964 0.534936
v 0.000000 2.006964 0.545416
v 0.106405 2.006964 0.534936
v 0.208721 2.006964 0.503899
v 0.303016 2.006964 0.453497
v 0.385667 2.006964 0.385668
v 0.453496 2.006964 0.303018
v 0.503898 2.006964 0.208723
v 0.534935 2.006964 0.106407
v 0.545415 2.006964 0.000002
v 0.534936 2.006964 -0.106403
v 0.503898 2.006964 -0.208720
v 0.453497 2.006964 -0.303015
v 0.385668 2.006964 -0.385665
v 0.303017 2.006964 -0.453495
v 0.208722 2.006964 -0.503897
v 0.106406 2.006964 -0.534934
v 0.000001 2.802455 -0.770136
v 0.150247 2.802455 -0.755338
v 0.294720 2.802455 -0.711512
v 0.427866 2.802455 -0.640344
v 0.544569 2.802455 -0.544567
v 0.640346 2.802455 -0.427863
v 0.711514 2.802455 -0.294716
v 0.755338 2.802455 -0.150244
v 0.770136 2.802455 0.000002
v 0.755338 2.802455 0.150248
v 0.711513 2.802455 0.294720
v 0.640344 2.802455 0.427866
v 0.544568 2.802455 0.544569
v 0.427864 2.802455 0.640345
v 0.294718 2.802455 0.711513
v 0.150246 2.802455 0.755338
v 0.000001 2.802455 0.770136
v -0.150245 2.802455 0.755339
v -0.294717 2.802455 0.711514
v -0.427863 2.802455 0.640346
v -0.544567 2.802455 0.544570
v -0.640344 2.802455 0.427867
v -0.711512 2.802455 0.294721
v -0.755338 2.802455 0.150249
v -0.770136 2.802455 0.000004
v -0.755339 2.802455 -0.150242
v -0.711515 2.802455 -0.294714
v -0.640347 2.802455 -0.427861
v -0.544572 2.802455 -0.544565
v -0.427869 2.802455 -0.640342
v -0.294723 2.802455 -0.711511
v -0.150251 2.802455 -0.755337
v -0.000000 2.802455 0.000000
vn -0.000000 -1.000000 0.000000
vn 0.095602 0.220624 -0.970662
vn 0.283132 0.220624 -0.933360
vn 0.459782 0.220624 -0.860189
vn 0.618762 0.220624 -0.753962
vn 0.753963 0.220624 -0.618760
vn 0.860190 0.220624 -0.459781
vn 0.933361 0.220624 -0.283131
vn 0.970662 0.220624 -0.095601
vn 0.970662 0.220624 0.095603
vn 0.933360 0.220624 0.283132
vn 0.860190 0.220624 0.459781
vn 0.753963 0.220624 0.618761
vn 0.618761 0.220624 0.753963
vn 0.459781 0.220624 0.860190
vn 0.283132 0.220624 0.933360
vn 0.095602 0.220624 0.970662
vn -0.095602 0.220624 0.970662
vn -0.283131 0.220624 0.933360
vn -0.459781 0.220624 0.860190
vn -0.618761 0.220624 0.753963
vn -0.753962 0.220624 0.618762
vn -0.860190 0.220624 0.459782
vn -0.933360 0.220624 0.283132
vn -0.970662 0.220624 0.095603
vn -0.970662 0.220624 -0.095601
vn -0.933361 0.220624 -0.283131
vn -0.860190 0.220624 -0.459780
vn -0.753963 0.220624 -0.618760
vn -0.618762 0.220624 -0.753962
vn -0.459782 0.220624 -0.860189
vn -0.283133 0.220624 -0.933360
vn -0.095602 0.220625 -0.970662
vn -0.098020 0.000000 -0.995184
vn -0.290291 0.000000 -0.956938
vn -0.471402 0.000000 -0.881918
vn -0.634398 0.000000 -0.773007
vn -0.773014 0.000000 -0.634389
vn -0.881924 0.000000 -0.471392
vn -0.956942 0.000000 -0.290280
vn -0.995185 0.000000 -0.098013
vn -0.995184 0.000000 0.098021
vn -0.956939 0.000000 0.290288
vn -0.881920 0.000000 0.471399
vn -0.773009 0.000000 0.634395
vn -0.634392 0.000000 0.773012
vn -0.471395 0.000000 0.881922
vn -0.290283 0.000000 0.956941
vn -0.098016 0.000000 0.995185
vn 0.098018 0.000000 0.995185
vn 0.290285 0.000000 0.956940
vn 0.471397 0.000000 0.881921
vn 0.634393 0.000000 0.773011
vn 0.773010 0.000000 0.634394
vn 0.881921 0.000000 0.471398
vn 0.956940 0.000000 0.290286
vn 0.995185 0.000000 0.098019
vn 0.995185 0.000000 -0.098015
vn 0.956941 0.000000 -0.290283
vn 0.881922 0.000000 -0.471395
vn 0.773012 0.000000 -0.634392
vn 0.634395 0.000000 -0.773009
vn 0.471398 0.000000 -0.881920
vn 0.290287 0.000000 -0.956940
vn 0.098019 0.000000 -0.995185
vn 0.094360 -0.270641 -0.958044
vn 0.279453 -0.270641 -0.921227
vn 0.453806 -0.270641 -0.849007
vn 0.610719 -0.270641 -0.744161
vn 0.744163 -0.270641 -0.610717
vn 0.849009 -0.270641 -0.453803
vn 0.921228 -0.270641 -0.279449
vn 0.958045 -0.270641 -0.094357
vn 0.958045 -0.270641 0.094361
vn 0.921227 -0.270641 0.279452
vn 0.849008 -0.270641 0.453806
vn 0.744162 -0.270641 0.610718
vn 0.610718 -0.270641 0.744162
vn 0.453804 -0.270641 0.849008
vn 0.279451 -0.270640 0.921228
vn 0.094360 -0.270640 0.958045
vn -0.094358 -0.270640 0.958045
vn -0.279450 -0.270640 0.921228
vn -0.453802 -0.270640 0.849010
vn -0.610716 -0.270641 0.744163
vn -0.744160 -0.270641 0.610720
vn -0.849007 -0.270641 0.453807
vn -0.921227 -0.270641 0.279455
vn -0.958044 -0.270641 0.094363
vn -0.958045 -0.270641 -0.094356
vn -0.921229 -0.270641 -0.279447
vn -0.849010 -0.270641 -0.453800
vn -0.744165 -0.270641 -0.610714
vn -0.610722 -0.270641 -0.744158
vn -0.453810 -0.270641 -0.849005
vn -0.279457 -0.270641 -0.921226
vn -0.094362 -0.270641 -0.958044
vn 0.000000 1.000000 -0.000000
usemtl
s off
f 65//1 1//1 2//1
f 65//1 2//1 3//1
f 65//1 3//1 4//1
f 65//1 4//1 5//1
f 65//1 5//1 6//1
f 65//1 6//1 7//1
f 65//1 7//1 8//1
f 65//1 8//1 9//1
f 65//1 9//1 10//1
f 65//1 10//1 11//1
f 65//1 11//1 12//1
f 65//1 12//1 13//1
f 65//1 13//1 14//1
f 65//1 14//1 15//1
f 65//1 15//1 16//1
f 65//1 16//1 17//1
f 65//1 17//1 18//1
f 65//1 18//1 19//1
f 65//1 19//1 20//1
f 65//1 20//1 21//1
f 65//1 21//1 22//1
f 65//1 22//1 23//1
f 65//1 23//1 24//1
f 65//1 24//1 25//1
f 65//1 25//1 26//1
f 65//1 26//1 27//1
f 65//1 27//1 28//1
f 65//1 28//1 29//1
f 65//1 29//1 30//1
f 65//1 30//1 31//1
f 65//1 31//1 32//1
f 32//1 1//1 65//1
f 1//2 33//2 34//2
f 1//2 34//2 2//2
f 2//3 34//3 35//3
f 2//3 35//3 3//3
f 3//4 35//4 36//4
f 3//4 36//4 4//4
f 4//5 36//5 37//5
f 4//5 37//5 5//5
f 5//6 37//6 38//6
f 5//6 38//6 6//6
f 6//7 38//7 39//7
f 6//7 39//7 7//7
f 7//8 39//8 40//8
f 7//8 40//8 8//8
f 8//9 40//9 41//9
f 8//9 41//9 9//9
f 9//10 41//10 42//10
f 9//10 42//10 10//10
f 10//11 42//11 43//11
f 10//11 43//11 11//11
f 11//12 43//12 44//12
f 11//12 44//12 12//12
f 12//13 44//13 45//13
f 12//13 45//13 13//13
f 13//14 45//14 46//14
f 13//14 46//14 14//14
f 14//15 46//15 47//15
f 14//15 47//15 15//15
f 15//16 47//16 48//16
f 15//16 48//16 16//16
f 16//17 48//17 49//17
f 16//17 49//17 17//17
f 17//18 49//18 50//18
f 17//18 50//18 18//18
f 18//19 50//19 51//19
f 18//19 51//19 19//19
f 19//20 51//20 52//20
f 19//20 52//20 20//20
f 20//21 52//21 53//21
f 20//21 53//21 21//21
f 21//22 53//22 54//22
f 21//22 54//22 22//22
f 22//23 54//23 55//23
f 22//23 55//23 23//23
f 23//24 55//24 56//24
f 23//24 56//24 24//24
f 24//25 56//25 57//25
f 24//25 57//25 25//25
f 25//26 57//26 58//26
f 25//26 58//26 26//26
f 26//27 58//27 59//27
f 26//27 59//27 27//27
f 27//28 59//28 60//28
f 27//28 60//28 28//28
f 28//29 60//29 61//29
f 28//29 61//29 29//29
f 29//30 61//30 62//30
f 29//30 62//30 30//30
f 30//31 62//31 63//31
f 30//31 63//31 31//31
f 31//32 63//32 64//32
f 31//32 64//32 32//32
f 33//33 1//33 32//33
f 33//33 32//33 64//33
f 33//34 64//34 67//34
f 33//34 67//34 66//34
f 64//35 63//35 68//35
f 64//35 68//35 67//35
f 63//36 62//36 69//36
f 63//36 69//36 68//36
f 62//37 61//37 70//37
f 62//37 70//37 69//37
f 61//38 60//38 71//38
f 61//38 71//38 70//38
f 60//39 59//39 72//39
f 60//39 72//39 71//39
f 59//40 58//40 73//40
f 59//40 73//40 72//40
f 58//41 57//41 74//41
f 58//41 74//41 73//41
f 57//42 56//42 75//42
f 57//42 75//42 74//42
f 56//43 55//43 76//43
f 56//43 76//43 75//43
f 55//44 54//44 77//44
f 55//44 77//44 76//44
f 54//45 53//45 78//45
f 54//45 78//45 77//45
f 53//46 52//46 79//46
f 53//46 79//46 78//46
f 52//47 51//47 80//47
f 52//47 80//47 79//47
f 51//48 50//48 81//48
f 51//48 81//48 80//48
f 50//49 49//49 82//49
f 50//49 82//49 81//49
f 49//50 48//50 83//50
f 49//50 83//50 82//50
f 48//51 47//51 84//51
f 48//51 84//51 83//51
f 47//52 46//52 85//52
f 47//52 85//52 84//52
f 46//53 45//53 86//53
f 46//53 86//53 85//53
f 45//54 44//54 87//54
f 45//54 87//54 86//54
f 44//55 43//55 88//55
f 44//55 88//55 87//55
f 43//56 42//56 89//56
f 43//56 89//56 88//56
f 42//57 41//57 90//57
f 42//57 90//57 89//57
f 41//58 40//58 91//58
f 41//58 91//58 90//58
f 40//59 39//59 92//59
f 40//59 92//59 91//59
f 39//60 38//60 93//60
f 39//60 93//60 92//60
f 38//61 37//61 94//61
f 38//61 94//61 93//61
f 37//62 36//62 95//62
f 37//62 95//62 94//62
f 36//63 35//63 96//63
f 36//63 96//63 95//63
f 35//64 34//64 97//64
f 35//64 97//64 96//64
f 34//65 33//65 66//65
f 34//65 66//65 97//65
f 97//66 66//66 98//66
f 97//66 98//66 99//66
f 96//67 97//67 99//67
f 96//67 99//67 100//67
f 95//68 96//68 100//68
f 95//68 100//68 101//68
f 94//69 95//69 101//69
f 94//69 101//69 102//69
f 93//70 94//70 102//70
f 93//70 102//70 103//70
f 92//71 93//71 103//71
f 92//71 103//71 104//71
f 91//72 92//72 104//72
f 91//72 104//72 105//72
f 90//73 91//73 105//73
f 90//73 105//73 106//73
f 89//74 90//74 106//74
f 89//74 106//74 107//74
f 88//75 89//75 107//75
f 88//75 107//75 108//75
f 87//76 88//76 108//76
f 87//76 108//76 109//76
f 86//77 87//77 109//77
f 86//77 109//77 110//77
f 85//78 86//78 110//78
f 85//78 110//78 111//78
f 84//79 85//79 111//79
f 84//79 111//79 112//79
f 83//80 84//80 112//80
f 83//80 112//80 113//80
f 82//81 83//81 113//81
f 82//81 113//81 114//81
f 81//82 82//82 114//82
f 81//82 114//82 115//82
f 80//83 81//83 115//83
f 80//83 115//83 116//83
f 79//84 80//84 116//84
f 79//84 116//84 117//84
f 78//85 79//85 117//85
f 78//85 117//85 118//85
f 77//86 78//86 118//86
f 77//86 118//86 119//86
f 76//87 77//87 119//87
f 76//87 119//87 120//87
f 75//88 76//88 120//88
f 75//88 120//88 121//88
f 74//89 75//89 121//89
f 74//89 121//89 122//89
f 73//90 74//90 122//90
f 73//90 122//90 123//90
f 72//91 73//91 123//91
f 72//91 123//91 124//91
f 71//92 72//92 124//92
f 71//92 124//92 125//92
f 70//93 71//93 125//93
f 70//93 125//93 126//93
f 69//94 70//94 126//94
f 69//94 126//94 127//94
f 68//95 69//95 127//95
f 68//95 127//95 128//95
f 67//96 68//96 128//96
f 67//96 128//96 129//96
f 66//97 67//97 129//97
f 66//97 129//97 98//97
f 130//98 99//98 98//98
f 130//98 100//98 99//98
f 130//98 101//98 100//98
f 130//98 102//98 101//98
f 130//98 103//98 102//98
f 130//98 104//98 103//98
f 130//98 105//98 104//98
f 130//98 106//98 105//98
f 130//98 107//98 106//98
f 130//98 108//98 107//98
f 130//98 109//98 108//98
f 130//98 110//98 109//98
f 130//98 111//98 110//98
f 130//98 112//98 111//98
f 130//98 113//98 112//98
f 130//98 114//98 113//98
f 130//98 115//98 114//98
f 130//98 116//98 115//98
f 130//98 117//98 116//98
f 130//98 118//98 117//98
f 130//98 119//98 118//98
f 130//98 120//98 119//98
f 130//98 121//98 120//98
f 130//98 122//98 121//98
f 130//98 123//98 122//98
f 130//98 124//98 123//98
f 130//98 125//98 124//98
f 130//98 126//98 125//98
f 130//98 127//98 126//98
f 130//98 128//98 127//98
f 130//98 129//98 128//98
f 130//98 98//98 129//98