Browse Source

Fixed illumination model conversion in the OBJ loader.
Added map_d support to obj.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@332 67173fc5-114c-0410-ac8e-9d2fd5bffc1f

aramis_acg 16 years ago
parent
commit
4048eb92f5
4 changed files with 37 additions and 4 deletions
  1. 8 2
      code/ObjFileData.h
  2. 21 1
      code/ObjFileImporter.cpp
  3. 6 1
      code/ObjFileMtlImporter.cpp
  4. 2 0
      include/aiMaterial.h

+ 8 - 2
code/ObjFileData.h

@@ -146,7 +146,7 @@ struct Object
 //!	\brief	Data structure to store all material specific data
 //!	\brief	Data structure to store all material specific data
 struct Material
 struct Material
 {
 {
-	//!	NAme of material description
+	//!	Name of material description
 	aiString MaterialName;
 	aiString MaterialName;
 
 
 	//!	Texture names
 	//!	Texture names
@@ -155,6 +155,7 @@ struct Material
 	aiString textureAmbient;
 	aiString textureAmbient;
 	aiString textureBump;
 	aiString textureBump;
 	aiString textureSpecularity;
 	aiString textureSpecularity;
+	aiString textureOpacity;
 
 
 	//!	Ambient color 
 	//!	Ambient color 
 	aiColor3D ambient;
 	aiColor3D ambient;
@@ -168,10 +169,15 @@ struct Material
 	float shineness;
 	float shineness;
 	//!	Illumination model 
 	//!	Illumination model 
 	int illumination_model;
 	int illumination_model;
+	//! Index of refraction
+	float ior;
 
 
 	//!	Constructor
 	//!	Constructor
 	Material()
 	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
 		// empty
 	}
 	}

+ 21 - 1
code/ObjFileImporter.cpp

@@ -431,7 +431,24 @@ void ObjFileImporter::createMaterial(const ObjFile::Model* pModel, const ObjFile
 
 
 		ObjFile::Material *pCurrentMaterial = (*it).second;
 		ObjFile::Material *pCurrentMaterial = (*it).second;
 		mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );
 		mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );
-		mat->AddProperty<int>( &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<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);
 
 
 		// Adding material colors
 		// Adding material colors
 		mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT );
 		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 )
 		if ( 0 != pCurrentMaterial->textureBump.length )
 			mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));
 			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 )
 		if ( 0 != pCurrentMaterial->textureSpecularity.length )
 			mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
 			mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));
 		
 		

+ 6 - 1
code/ObjFileMtlImporter.cpp

@@ -141,7 +141,8 @@ void ObjFileMtlImporter::load()
 					getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
 					getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
 					break;
 					break;
 				case 'i': //Index Of refraction 
 				case 'i': //Index Of refraction 
-					//TODO
+					++m_DataIt;
+					getFloatValue(m_pModel->m_pCurrentMaterial->ior);
 					break;
 					break;
 				}
 				}
 				m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
 				m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
@@ -260,6 +261,10 @@ void ObjFileMtlImporter::getTexture()
 	else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ks",6))
 	else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ks",6))
 		out = & m_pModel->m_pCurrentMaterial->textureSpecular;
 		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
 	// Ambient texture
 	else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ka",6))
 	else if (!ASSIMP_strincmp(&(*m_DataIt),"map_ka",6))
 		out = & m_pModel->m_pCurrentMaterial->textureAmbient;
 		out = & m_pModel->m_pCurrentMaterial->textureAmbient;

+ 2 - 0
include/aiMaterial.h

@@ -636,6 +636,8 @@ extern "C" {
 /** @def AI_MATKEY_SHININESS
 /** @def AI_MATKEY_SHININESS
  *  Defines the base shininess of the material
  *  Defines the base shininess of the material
  *  This is the exponent of the Phong shading equation.
  *  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.
  * <br>
  * <br>
  * <b>Type:</b> float<br>
  * <b>Type:</b> float<br>
  * <b>Default value:</b> 0.0f <br>
  * <b>Default value:</b> 0.0f <br>