Ogre: MaterialLoader now searches for Materialfile with the MaterialName as Filename

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1192 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/head
jonathanklein 2012-03-09 11:42:47 +00:00
parent 6970307b4e
commit 005887f381
1 changed files with 27 additions and 18 deletions

View File

@ -119,33 +119,36 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const
}
*/
//the filename typically ends with .mesh or .mesh.xml
const string MaterialFileName=m_CurrentFilename.substr(0, m_CurrentFilename.rfind(".mesh"))+".material";
DefaultLogger::get()->info("Trying to load " + MaterialFileName);
aiMaterial *NewMaterial=new aiMaterial();
aiString ts(MaterialName.c_str());
NewMaterial->AddProperty(&ts, AI_MATKEY_NAME);
//Read the file into memory and put it in a stringstream
stringstream ss;
{// after this block, the temporarly loaded data will be released
IOStream* MatFilePtr=m_CurrentIOHandler->Open(MaterialFileName);
/*
We have 3 guesses for the Material filename:
- the Material Name
- the Name of the mesh file
- the DefaultMaterialLib (which you can set before importing)
*/
IOStream* MatFilePtr=m_CurrentIOHandler->Open(MaterialName+".material");
if(NULL==MatFilePtr)
{
//try the default mat Library
//the filename typically ends with .mesh or .mesh.xml
const string MaterialFileName=m_CurrentFilename.substr(0, m_CurrentFilename.rfind(".mesh"))+".material";
IOStream* MatFilePtr=m_CurrentIOHandler->Open(MaterialFileName);
if(NULL==MatFilePtr)
{
MatFilePtr=m_CurrentIOHandler->Open(m_MaterialLibFilename);
//try the default mat Library
if(NULL==MatFilePtr)
{
DefaultLogger::get()->error(m_MaterialLibFilename+" and "+MaterialFileName + " could not be opened, Material will not be loaded!");
delete NewMaterial;
return NULL;
MatFilePtr=m_CurrentIOHandler->Open(m_MaterialLibFilename);
if(NULL==MatFilePtr)
{
DefaultLogger::get()->error(m_MaterialLibFilename+" and "+MaterialFileName + " could not be opened, Material will not be loaded!");
return NULL;
}
}
}
}
@ -157,6 +160,12 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const
ss << &FileData[0];
}
//create the material
aiMaterial *NewMaterial=new aiMaterial();
aiString ts(MaterialName.c_str());
NewMaterial->AddProperty(&ts, AI_MATKEY_NAME);
string Line;
ss >> Line;
// unsigned int Level=0;//Hierarchielevels in the material file, like { } blocks into another