mirror of
https://github.com/minetest/irrlicht.git
synced 2024-11-14 19:53:46 +01:00
ffd7b63af0
C++ has undefined behavior for identifiers starting with __ or with _ followed by an uppercase letter. We still have many more (in IrrCompileConfig.h and in all header-guards), will likely replace those later as well. As a workaround for users which might use irrlicht defines in their code, I've added the header irrLegacyDefines.h Including that allows to continue using old defines for a while - or make it easier to have code which compiles with old and new Irrlicht library versions. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6251 dfc29bdd-3216-0410-991c-e03cc46cb475
128 lines
3.4 KiB
C++
128 lines
3.4 KiB
C++
#include "CMeshTextureLoader.h"
|
|
#include "IFileSystem.h"
|
|
#include "IVideoDriver.h"
|
|
|
|
namespace irr
|
|
{
|
|
namespace scene
|
|
{
|
|
|
|
CMeshTextureLoader::CMeshTextureLoader(irr::io::IFileSystem* fs, irr::video::IVideoDriver* driver)
|
|
: FileSystem(fs)
|
|
, VideoDriver(driver)
|
|
, MeshFile(0)
|
|
, MaterialFile(0)
|
|
{
|
|
}
|
|
|
|
//! Set a custom texture path.
|
|
void CMeshTextureLoader::setTexturePath(const irr::io::path& path)
|
|
{
|
|
TexturePath = path;
|
|
preparePath(TexturePath);
|
|
}
|
|
|
|
//! Get the current custom texture path.
|
|
const irr::io::path& CMeshTextureLoader::getTexturePath() const
|
|
{
|
|
return TexturePath;
|
|
}
|
|
|
|
bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename)
|
|
{
|
|
if (FileSystem->existFile(filename))
|
|
{
|
|
TextureName = filename;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//! Get the texture by searching for it in all paths that makes sense for the given textureName.
|
|
irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textureName)
|
|
{
|
|
if ( textureName.empty() || !FileSystem || !VideoDriver)
|
|
return NULL;
|
|
|
|
// Pre-process texture filename.
|
|
irr::io::path simplifiedTexName(textureName);
|
|
simplifiedTexName.replace(IRR_TEXT('\\'),IRR_TEXT('/'));
|
|
|
|
// user defined texture path
|
|
if ( !TexturePath.empty() )
|
|
{
|
|
if ( checkTextureName(TexturePath + simplifiedTexName) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
|
|
if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName)) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
}
|
|
|
|
// just the name itself
|
|
if ( checkTextureName(simplifiedTexName) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
|
|
// look in files relative to the folder of the meshfile
|
|
if ( MeshFile )
|
|
{
|
|
if ( MeshPath.empty() )
|
|
{
|
|
MeshPath = FileSystem->getFileDir(MeshFile->getFileName());
|
|
preparePath(MeshPath);
|
|
}
|
|
if ( !MeshPath.empty() )
|
|
{
|
|
if ( checkTextureName(MeshPath + simplifiedTexName) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
|
|
if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName)) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
}
|
|
}
|
|
|
|
// look in files relative to the folder of the materialfile
|
|
if ( MaterialFile )
|
|
{
|
|
if ( MaterialPath.empty() )
|
|
{
|
|
MaterialPath = FileSystem->getFileDir(MaterialFile->getFileName());
|
|
preparePath(MaterialPath);
|
|
}
|
|
if ( !MaterialPath.empty() )
|
|
{
|
|
if ( checkTextureName(MaterialPath + simplifiedTexName) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
|
|
if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName)) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
}
|
|
}
|
|
|
|
// check current working directory
|
|
if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName)) )
|
|
return VideoDriver->getTexture(TextureName);
|
|
|
|
TextureName = IRR_TEXT("");
|
|
return NULL;
|
|
}
|
|
|
|
//! Meshloaders will search paths relative to the meshFile.
|
|
void CMeshTextureLoader::setMeshFile(const irr::io::IReadFile* meshFile)
|
|
{
|
|
// no grab (would need a weak_ptr)
|
|
MeshFile = meshFile;
|
|
MeshPath = IRR_TEXT(""); // do a lazy evaluation later
|
|
}
|
|
|
|
//! Meshloaders will try to look relative to the path of the materialFile
|
|
void CMeshTextureLoader::setMaterialFile(const irr::io::IReadFile* materialFile)
|
|
{
|
|
// no grab (would need a weak_ptr)
|
|
MaterialFile = materialFile;
|
|
MaterialPath = IRR_TEXT(""); // do a lazy evaluation later
|
|
}
|
|
|
|
} // end namespace scnene
|
|
} // end namespace irr
|