diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 61fc7ca76..9726ae088 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -146,7 +146,7 @@ struct Object //! \brief Data structure to store all material specific data struct Material { - //! NAme of material description + //! Name of material description aiString MaterialName; //! Texture names @@ -155,6 +155,7 @@ struct Material aiString textureAmbient; aiString textureBump; aiString textureSpecularity; + aiString textureOpacity; //! Ambient color aiColor3D ambient; @@ -168,10 +169,15 @@ struct Material float shineness; //! Illumination model int illumination_model; + //! Index of refraction + float ior; //! Constructor Material() - : diffuse(0.6f,0.6f,0.6f) + : diffuse (0.6f,0.6f,0.6f) + , ior (1.f) + , alpha (1.f) + , illumination_model (1) { // empty } diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 94d8cffd3..72c668026 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -431,7 +431,24 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile ObjFile::Material *pCurrentMaterial = (*it).second; mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME ); - mat->AddProperty( &pCurrentMaterial->illumination_model, 1, AI_MATKEY_SHADING_MODEL); + + // convert illumination model + int sm; + switch (pCurrentMaterial->illumination_model) { + case 0: + sm = aiShadingMode_NoShading; + break; + case 1: + sm = aiShadingMode_Gouraud; + break; + case 2: + sm = aiShadingMode_Phong; + break; + default: + sm = aiShadingMode_Gouraud; + DefaultLogger::get()->error("OBJ/MTL: Unexpected illumination model (0-3 recognized)"); + } + mat->AddProperty( &sm, 1, AI_MATKEY_SHADING_MODEL); // Adding material colors mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT ); @@ -452,6 +469,9 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile if ( 0 != pCurrentMaterial->textureBump.length ) mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0)); + if ( 0 != pCurrentMaterial->textureOpacity.length ) + mat->AddProperty( &pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0)); + if ( 0 != pCurrentMaterial->textureSpecularity.length ) mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0)); diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index 47385379a..f979ce18d 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -141,7 +141,8 @@ void ObjFileMtlImporter::load() getFloatValue(m_pModel->m_pCurrentMaterial->shineness); break; case 'i': //Index Of refraction - //TODO + ++m_DataIt; + getFloatValue(m_pModel->m_pCurrentMaterial->ior); break; } m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); @@ -260,6 +261,10 @@ void ObjFileMtlImporter::getTexture() else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ks",6)) out = & m_pModel->m_pCurrentMaterial->textureSpecular; + // Opacity texture + else if (!ASSIMP_strincmp(&(*m_DataIt),"map_d",5)) + out = & m_pModel->m_pCurrentMaterial->textureOpacity; + // Ambient texture else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ka",6)) out = & m_pModel->m_pCurrentMaterial->textureAmbient; diff --git a/include/aiMaterial.h b/include/aiMaterial.h index 8179400d9..af394cf6a 100644 --- a/include/aiMaterial.h +++ b/include/aiMaterial.h @@ -636,6 +636,8 @@ extern "C" { /** @def AI_MATKEY_SHININESS * Defines the base shininess of the material * This is the exponent of the Phong shading equation. + * The range of this value depends on the file format, but usually + * you can assume that you won't get higher valzes than 128. *
* Type: float
* Default value: 0.0f