Ogre: Importerproperty to set Texture Mode from Filename (bla_n.png -> Normalmap etc.)

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1254 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/merge
jonathanklein 2012-06-03 18:01:32 +00:00
parent 5b462d484b
commit 29243071fa
5 changed files with 98 additions and 9 deletions

View File

@ -244,6 +244,7 @@ const aiImporterDesc* OgreImporter::GetInfo () const
void OgreImporter::SetupProperties(const Importer* pImp) void OgreImporter::SetupProperties(const Importer* pImp)
{ {
m_MaterialLibFilename=pImp->GetPropertyString(AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE, "Scene.material"); m_MaterialLibFilename=pImp->GetPropertyString(AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE, "Scene.material");
m_TextureTypeFromFilename=pImp->GetPropertyBool(AI_CONFIG_IMPORT_OGRE_TEXTURETYPE_FROM_FILENAME, false);
} }

View File

@ -93,7 +93,7 @@ private:
//-------------------------------- OgreMaterial.cpp ------------------------------- //-------------------------------- OgreMaterial.cpp -------------------------------
aiMaterial* LoadMaterial(const std::string MaterialName) const; 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 //Now we don't have to give theses parameters to all functions
std::string m_CurrentFilename; std::string m_CurrentFilename;
std::string m_MaterialLibFilename; std::string m_MaterialLibFilename;
bool m_TextureTypeFromFilename;
IOSystem* m_CurrentIOHandler; IOSystem* m_CurrentIOHandler;
aiScene *m_CurrentScene; aiScene *m_CurrentScene;
SubMesh m_SharedGeometry;///< we will just use the vertexbuffers of the submesh SubMesh m_SharedGeometry;///< we will just use the vertexbuffers of the submesh

View File

@ -276,9 +276,12 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const
return NewMaterial; 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; string RestOfLine;
@ -338,6 +341,11 @@ void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial)
else if(Line=="texture_unit") else if(Line=="texture_unit")
{ {
getline(ss, RestOfLine);//ignore the rest of the line getline(ss, RestOfLine);//ignore the rest of the line
std::string TextureName;
int TextureType=-1;
int UvSet=0;
ss >> Line; ss >> Line;
if(Line!="{") if(Line!="{")
throw DeadlyImportError("empty texture unit!"); throw DeadlyImportError("empty texture unit!");
@ -347,17 +355,39 @@ void OgreImporter::ReadTechnique(stringstream &ss, aiMaterial* NewMaterial)
if(Line=="texture") if(Line=="texture")
{ {
ss >> Line; ss >> Line;
aiString ts(Line.c_str()); TextureName=Line;
NewMaterial->AddProperty(&ts, AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, CurrentTextureId));
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") else if(Line=="tex_coord_set")
{ {
int UvSet;
ss >> 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; ss >> Line;
if("replace"==Line)//I don't think, assimp has something for this... 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 //TODO: set value
//NewMaterial->AddProperty(aiTextureOp_Multiply) //NewMaterial->AddProperty(aiTextureOp_Multiply)
} }
*/
} }
}//end of texture unit }//end of texture unit
Line="";//clear the } that would end the outer loop 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 Line="";//clear the } that would end the outer loop

View File

@ -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. 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 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.
<br>
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.
<br>
Property type: String. Default value: guessed.
@subsection todo Todo @subsection todo Todo
- Load colors in custom materials - Load colors in custom materials
- extend custom and normal material loading - extend custom and normal material loading

View File

@ -686,6 +686,19 @@ enum aiComponent
#define AI_CONFIG_IMPORT_OGRE_MATERIAL_FILE "IMPORT_OGRE_MATERIAL_FILE" #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.
* <br>
* 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. /** @brief Specifies whether the IFC loader skips over IfcSpace elements.
* *