diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index 736f200b9..e08c1776e 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -244,6 +244,7 @@ const aiImporterDesc* OgreImporter::GetInfo () const void OgreImporter::SetupProperties(const Importer* pImp) { m_MaterialLibFilename=pImp->GetPropertyString(AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE, "Scene.material"); + m_TextureTypeFromFilename=pImp->GetPropertyBool(AI_CONFIG_IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME, false); } diff --git a/code/OgreImporter.hpp b/code/OgreImporter.hpp index 80a12f28a..20f3bc576 100644 --- a/code/OgreImporter.hpp +++ b/code/OgreImporter.hpp @@ -93,7 +93,7 @@ private: //-------------------------------- OgreMaterial.cpp ------------------------------- aiMaterial* LoadMaterial(const std::string MaterialName) const; - static void ReadTechnique(std::stringstream &ss, aiMaterial* NewMaterial); + void ReadTechnique(std::stringstream &ss, aiMaterial* NewMaterial) const; @@ -101,6 +101,7 @@ private: //Now we don't have to give theses parameters to all functions std::string m_CurrentFilename; std::string m_MaterialLibFilename; + bool m_TextureTypeFromFilename; IOSystem* m_CurrentIOHandler; aiScene *m_CurrentScene; SubMesh m_SharedGeometry;///< we will just use the vertexbuffers of the submesh diff --git a/code/OgreMaterial.cpp b/code/OgreMaterial.cpp index eab92ad48..95ca1cf42 100644 --- a/code/OgreMaterial.cpp +++ b/code/OgreMaterial.cpp @@ -276,9 +276,12 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const return NewMaterial; } -void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial) +void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial) const { - unsigned int CurrentTextureId=0; + unsigned int CurrentDiffuseTextureId=0; + unsigned int CurrentSpecularTextureId=0; + unsigned int CurrentNormalTextureId=0; + unsigned int CurrentLightTextureId=0; string RestOfLine; @@ -338,6 +341,11 @@ void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial) else if(Line=="texture_unit") { getline(ss, RestOfLine);//ignore the rest of the line + + std::string TextureName; + int TextureType=-1; + int UvSet=0; + ss >> Line; if(Line!="{") throw DeadlyImportError("empty texture unit!"); @@ -347,17 +355,39 @@ void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial) if(Line=="texture") { ss >> Line; - aiString ts(Line.c_str()); - NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, CurrentTextureId)); + TextureName=Line; + + if(m_TextureTypeFromFilename) + { + if(Line.find("_n.")!=string::npos)// Normalmap + { + TextureType=aiTextureType_NORMALS; + } + else if(Line.find("_s.")!=string::npos)// Specularmap + { + TextureType=aiTextureType_SPECULAR; + } + else if(Line.find("_l.")!=string::npos)// Lightmap + { + TextureType=aiTextureType_LIGHTMAP; + } + else// colormap + { + TextureType=aiTextureType_DIFFUSE; + } + } + else + { + TextureType=aiTextureType_DIFFUSE; + } } else if(Line=="tex_coord_set") { - int UvSet; ss >> UvSet; - NewMaterial->AddProperty(&UvSet, 1, AI_MATKEY_UVWSRC(0, CurrentTextureId)); } - else if(Line=="colour_op") + else if(Line=="colour_op")//TODO implement this { + /* ss >> Line; if("replace"==Line)//I don't think, assimp has something for this... { @@ -367,11 +397,41 @@ void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial) //TODO: set value //NewMaterial->AddProperty(aiTextureOp_Multiply) } + */ } }//end of texture unit Line="";//clear the } that would end the outer loop - CurrentTextureId++;//new Id for the next texture + + //give the texture to assimp: + + aiString ts(TextureName.c_str()); + switch(TextureType) + { + case aiTextureType_DIFFUSE: + NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, CurrentDiffuseTextureId)); + NewMaterial->AddProperty(&UvSet, 1, AI_MATKEY_UVWSRC(0, CurrentDiffuseTextureId)); + CurrentDiffuseTextureId++; + break; + case aiTextureType_NORMALS: + NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_NORMALS, CurrentNormalTextureId)); + NewMaterial->AddProperty(&UvSet, 1, AI_MATKEY_UVWSRC(0, CurrentNormalTextureId)); + CurrentNormalTextureId++; + break; + case aiTextureType_SPECULAR: + NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_SPECULAR, CurrentSpecularTextureId)); + NewMaterial->AddProperty(&UvSet, 1, AI_MATKEY_UVWSRC(0, CurrentSpecularTextureId)); + CurrentSpecularTextureId++; + break; + case aiTextureType_LIGHTMAP: + NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_LIGHTMAP, CurrentLightTextureId)); + NewMaterial->AddProperty(&UvSet, 1, AI_MATKEY_UVWSRC(0, CurrentLightTextureId)); + CurrentLightTextureId++; + break; + default: + DefaultLogger::get()->warn("Invalid Texture Type!"); + break; + } } } Line="";//clear the } that would end the outer loop diff --git a/doc/dox.h b/doc/dox.h index 1477139e4..40db0ddad 100644 --- a/doc/dox.h +++ b/doc/dox.h @@ -1473,6 +1473,20 @@ can find in scripts/OgreImpoter/Assimp.tlp in the assimp source. If you don't se If you want more properties in custom materials, you can easily expand the ogre material loader, it will be just a few lines for each property. Just look in OgreImporterMaterial.cpp +@subsection Importer Properties +- IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME: Normally, a texture is loaded as a colormap, if no + target is specified in the + materialfile. Is this switch is enabled, texture names ending with _n, _l, _s + are used as normalmaps, lightmaps or specularmaps. +
+ Property type: Bool. Default value: false. +- IMPORT_OGRE_MATERIAL_FILE: Ogre Meshes contain only the MaterialName, not the MaterialFile. + If there + is no material file with the same name as the material, Ogre Importer will + try to load this file and search the material in it. +
+ Property type: String. Default value: guessed. + @subsection todo Todo - Load colors in custom materials - extend custom and normal material loading diff --git a/include/assimp/config.h b/include/assimp/config.h index 73e41ca2f..9c4fef0f8 100644 --- a/include/assimp/config.h +++ b/include/assimp/config.h @@ -686,6 +686,19 @@ enum aiComponent #define AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE "IMPORT_OGRE_MATERIAL_FILE" +// --------------------------------------------------------------------------- +/** @brief Ogre Importer detect the texture usage from its filename + * + * Normally, a texture is loaded as a colormap, if no target is specified in the + * materialfile. Is this switch is enabled, texture names ending with _n, _l, _s + * are used as normalmaps, lightmaps or specularmaps. + *
+ * Property type: Bool. Default value: false. + */ +#define AI_CONFIG_IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME "IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME" + + + // --------------------------------------------------------------------------- /** @brief Specifies whether the IFC loader skips over IfcSpace elements. *