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-9d2fd5bffc1fpull/5/head
parent
6970307b4e
commit
005887f381
|
@ -119,20 +119,23 @@ 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
|
//Read the file into memory and put it in a stringstream
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
{// after this block, the temporarly loaded data will be released
|
{// after this block, the temporarly loaded data will be released
|
||||||
|
|
||||||
|
/*
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
//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);
|
IOStream* MatFilePtr=m_CurrentIOHandler->Open(MaterialFileName);
|
||||||
if(NULL==MatFilePtr)
|
if(NULL==MatFilePtr)
|
||||||
{
|
{
|
||||||
|
@ -144,11 +147,11 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const
|
||||||
if(NULL==MatFilePtr)
|
if(NULL==MatFilePtr)
|
||||||
{
|
{
|
||||||
DefaultLogger::get()->error(m_MaterialLibFilename+" and "+MaterialFileName + " could not be opened, Material will not be loaded!");
|
DefaultLogger::get()->error(m_MaterialLibFilename+" and "+MaterialFileName + " could not be opened, Material will not be loaded!");
|
||||||
delete NewMaterial;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
boost::scoped_ptr<IOStream> MaterialFile(MatFilePtr);
|
boost::scoped_ptr<IOStream> MaterialFile(MatFilePtr);
|
||||||
vector<char> FileData(MaterialFile->FileSize());
|
vector<char> FileData(MaterialFile->FileSize());
|
||||||
MaterialFile->Read(&FileData[0], MaterialFile->FileSize(), 1);
|
MaterialFile->Read(&FileData[0], MaterialFile->FileSize(), 1);
|
||||||
|
@ -157,6 +160,12 @@ aiMaterial* OgreImporter::LoadMaterial(const std::string MaterialName) const
|
||||||
ss << &FileData[0];
|
ss << &FileData[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//create the material
|
||||||
|
aiMaterial *NewMaterial=new aiMaterial();
|
||||||
|
|
||||||
|
aiString ts(MaterialName.c_str());
|
||||||
|
NewMaterial->AddProperty(&ts, AI_MATKEY_NAME);
|
||||||
|
|
||||||
string Line;
|
string Line;
|
||||||
ss >> Line;
|
ss >> Line;
|
||||||
// unsigned int Level=0;//Hierarchielevels in the material file, like { } blocks into another
|
// unsigned int Level=0;//Hierarchielevels in the material file, like { } blocks into another
|
||||||
|
|
Loading…
Reference in New Issue