Merge pull request #1818 from jfaust/bugfix/c4d_obj_export_mtllib_after_g

Fix material index off-by-one error in some OBJ files
pull/1821/head
Kim Kulling 2018-03-05 18:54:32 +01:00 committed by GitHub
commit 81474e6d9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 2 deletions

View File

@ -303,11 +303,12 @@ void ObjFileMtlImporter::createMaterial()
// New Material created
m_pModel->m_pCurrentMaterial = new ObjFile::Material();
m_pModel->m_pCurrentMaterial->MaterialName.Set( name );
m_pModel->m_MaterialLib.push_back( name );
m_pModel->m_MaterialMap[ name ] = m_pModel->m_pCurrentMaterial;
if (m_pModel->m_pCurrentMesh) {
m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
}
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

@ -0,0 +1,5 @@
newmtl MyMaterial
Ka 1.000 1.000 1.000
Kd 1.000 1.000 1.000
Ns 200.000
Ks 0.050 0.050 0.050

View File

@ -0,0 +1,32 @@
g Object
mtllib cube_mtllib_after_g.mat
usemtl MyMaterial
v 0.0 0.0 0.0
v 0.0 0.0 1.0
v 0.0 1.0 0.0
v 0.0 1.0 1.0
v 1.0 0.0 0.0
v 1.0 0.0 1.0
v 1.0 1.0 0.0
v 1.0 1.0 1.0
vn 0.0 0.0 1.0
vn 0.0 0.0 -1.0
vn 0.0 1.0 0.0
vn 0.0 -1.0 0.0
vn 1.0 0.0 0.0
vn -1.0 0.0 0.0
f 1//2 7//2 5//2
f 1//2 3//2 7//2
f 1//6 4//6 3//6
f 1//6 2//6 4//6
f 3//3 8//3 7//3
f 3//3 4//3 8//3
f 5//5 7//5 8//5
f 5//5 8//5 6//5
f 1//4 5//4 6//4
f 1//4 6//4 2//4
f 2//1 6//1 8//1
f 2//1 8//1 4//1

View File

@ -354,3 +354,16 @@ TEST_F(utObjImportExport, 0based_array_Test) {
const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), 0);
EXPECT_EQ(nullptr, scene);
}
TEST_F( utObjImportExport, mtllib_after_g ) {
::Assimp::Importer importer;
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/OBJ/cube_mtllib_after_g.obj", aiProcess_ValidateDataStructure );
ASSERT_NE( nullptr, scene );
EXPECT_EQ(scene->mNumMeshes, 1U);
const aiMesh *mesh = scene->mMeshes[0];
const aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex];
aiString name;
ASSERT_EQ(aiReturn_SUCCESS, mat->Get(AI_MATKEY_NAME, name));
EXPECT_STREQ("MyMaterial", name.C_Str());
}