IMeshTextureLoader could be simplified further with the recent ITexture addition.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4706 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
359ae63b53
commit
4d45ef2ec7
|
@ -31,10 +31,6 @@ class IMeshTextureLoader : public virtual IReferenceCounted
|
|||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
IMeshTextureLoader() : CheckForCachedTextures(false)
|
||||
{}
|
||||
|
||||
//! Destructor
|
||||
virtual ~IMeshTextureLoader() {}
|
||||
|
||||
|
@ -51,13 +47,6 @@ public:
|
|||
\return Pointer to the texture. Returns 0 if loading failed.*/
|
||||
virtual irr::video::ITexture* getTexture(const irr::io::path& textureName) = 0;
|
||||
|
||||
//! Check if the last call to getTexture found a texture which was already cached.
|
||||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
This will only work when a) CheckForCachedTextures is set to true and b) getTexture was
|
||||
successful.
|
||||
\return When true the textuer was already cached. When false the texture was loaded newly. */
|
||||
virtual bool wasRecentTextureInCache() const = 0;
|
||||
|
||||
//! Meshloaders will search paths relative to the meshFile.
|
||||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
Any values you set here will likely be overwritten internally. */
|
||||
|
@ -67,25 +56,6 @@ public:
|
|||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
Any values you set here will likely be overwritten internally. */
|
||||
virtual void setMaterialFile(const irr::io::IReadFile* materialFile) = 0;
|
||||
|
||||
//! Enable checking if a texture was already cached before loading.
|
||||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
It's mostly used to modify texture when they are first loaded.
|
||||
\param enableCacheCheck On true getTexture calls will update information
|
||||
which can be received by wasRecentTextureInCache.*/
|
||||
void setCheckForCachedTextures(bool enableCacheCheck)
|
||||
{
|
||||
CheckForCachedTextures = enableCacheCheck;
|
||||
}
|
||||
|
||||
//! Are checks enabled which look if textures where cached before loading
|
||||
bool getCheckForCachedTextures() const
|
||||
{
|
||||
return CheckForCachedTextures;
|
||||
}
|
||||
|
||||
private:
|
||||
bool CheckForCachedTextures;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ CMeshTextureLoader::CMeshTextureLoader(irr::io::IFileSystem* fs, irr::video::IVi
|
|||
, VideoDriver(driver)
|
||||
, MeshFile(0)
|
||||
, MaterialFile(0)
|
||||
, WasRecentTextureCached(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -29,12 +28,11 @@ const irr::io::path& CMeshTextureLoader::getTexturePath() const
|
|||
return TexturePath;
|
||||
}
|
||||
|
||||
bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename, bool checkCache)
|
||||
bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename)
|
||||
{
|
||||
if (FileSystem->existFile(filename))
|
||||
{
|
||||
TextureName = filename;
|
||||
WasRecentTextureCached = checkCache && VideoDriver->findTexture(TextureName) != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -51,20 +49,18 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
|
|||
irr::io::path simplifiedTexName(textureName);
|
||||
simplifiedTexName.replace(_IRR_TEXT('\\'),_IRR_TEXT('/'));
|
||||
|
||||
bool checkCache = getCheckForCachedTextures();
|
||||
|
||||
// user defined texture path
|
||||
if ( !TexturePath.empty() )
|
||||
{
|
||||
if ( checkTextureName(TexturePath + simplifiedTexName, checkCache) )
|
||||
if ( checkTextureName(TexturePath + simplifiedTexName) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
|
||||
if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName), checkCache) )
|
||||
if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName)) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
}
|
||||
|
||||
// just the name itself
|
||||
if ( checkTextureName(simplifiedTexName, checkCache) )
|
||||
if ( checkTextureName(simplifiedTexName) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
|
||||
// look in files relative to the folder of the meshfile
|
||||
|
@ -77,10 +73,10 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
|
|||
}
|
||||
if ( !MeshPath.empty() )
|
||||
{
|
||||
if ( checkTextureName(MeshPath + simplifiedTexName, checkCache) )
|
||||
if ( checkTextureName(MeshPath + simplifiedTexName) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
|
||||
if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName), checkCache) )
|
||||
if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName)) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
}
|
||||
}
|
||||
|
@ -95,28 +91,22 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
|
|||
}
|
||||
if ( !MaterialPath.empty() )
|
||||
{
|
||||
if ( checkTextureName(MaterialPath + simplifiedTexName, checkCache) )
|
||||
if ( checkTextureName(MaterialPath + simplifiedTexName) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
|
||||
if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName), checkCache) )
|
||||
if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName)) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
}
|
||||
}
|
||||
|
||||
// check current working directory
|
||||
if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName), checkCache) )
|
||||
if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName)) )
|
||||
return VideoDriver->getTexture(TextureName);
|
||||
|
||||
TextureName = _IRR_TEXT("");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//! Check if the last call to getTexture found a texture which was already cached.
|
||||
bool CMeshTextureLoader::wasRecentTextureInCache() const
|
||||
{
|
||||
return WasRecentTextureCached;
|
||||
}
|
||||
|
||||
//! Meshloaders will search paths relative to the meshFile.
|
||||
void CMeshTextureLoader::setMeshFile(const irr::io::IReadFile* meshFile)
|
||||
{
|
||||
|
|
|
@ -35,13 +35,6 @@ public:
|
|||
\return Pointer to the texture. Returns 0 if loading failed.*/
|
||||
virtual irr::video::ITexture* getTexture(const irr::io::path& textureName) _IRR_OVERRIDE_;
|
||||
|
||||
//! Check if the last call to getTexture found a texture which was already cached.
|
||||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
This will only work when a) CheckForCachedTextures is set to true and b) getTexture was
|
||||
successful.
|
||||
\return When true the textuer was already cached. When false the texture was loaded newly. */
|
||||
virtual bool wasRecentTextureInCache() const _IRR_OVERRIDE_;
|
||||
|
||||
//! Meshloaders will search paths relative to the meshFile.
|
||||
/** Usually you do not have to use this method, it is used internally by IMeshLoader's.
|
||||
Any values you set here will likely be overwritten internally. */
|
||||
|
@ -68,7 +61,7 @@ protected:
|
|||
}
|
||||
|
||||
// Save the texturename when it's a an existing file
|
||||
bool checkTextureName( const irr::io::path& filename, bool checkCache);
|
||||
bool checkTextureName( const irr::io::path& filename);
|
||||
|
||||
private:
|
||||
irr::io::IFileSystem * FileSystem;
|
||||
|
@ -79,7 +72,6 @@ private:
|
|||
const irr::io::IReadFile* MaterialFile;
|
||||
irr::io::path MaterialPath;
|
||||
irr::io::path TextureName;
|
||||
bool WasRecentTextureCached;
|
||||
};
|
||||
|
||||
} // end namespace scene
|
||||
|
|
|
@ -429,21 +429,16 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
|
|||
currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP);
|
||||
|
||||
io::path texname(textureNameBuf);
|
||||
video::ITexture * texture = 0;
|
||||
bool newTexture=false;
|
||||
if (texname.size() && getMeshTextureLoader())
|
||||
{
|
||||
texture = getMeshTextureLoader()->getTexture(texname);
|
||||
newTexture = !getMeshTextureLoader()->wasRecentTextureInCache();
|
||||
|
||||
}
|
||||
video::ITexture * texture = getMeshTextureLoader()->getTexture(texname);
|
||||
if ( texture )
|
||||
{
|
||||
if (type==0)
|
||||
currMaterial->Meshbuffer->Material.setTexture(0, texture);
|
||||
else if (type==1)
|
||||
{
|
||||
if (newTexture)
|
||||
if ( texture->getSource() == video::ETS_FROM_FILE)
|
||||
SceneManager->getVideoDriver()->makeNormalMapTexture(texture, bumpiness);
|
||||
currMaterial->Meshbuffer->Material.setTexture(1, texture);
|
||||
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_PARALLAX_MAP_SOLID;
|
||||
|
@ -456,8 +451,8 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
|
|||
}
|
||||
else if (type==3)
|
||||
{
|
||||
// currMaterial->Meshbuffer->Material.Textures[1] = texture;
|
||||
// currMaterial->Meshbuffer->Material.MaterialType=video::EMT_REFLECTION_2_LAYER;
|
||||
// currMaterial->Meshbuffer->Material.Textures[1] = texture;
|
||||
// currMaterial->Meshbuffer->Material.MaterialType=video::EMT_REFLECTION_2_LAYER;
|
||||
}
|
||||
// Set diffuse material color to white so as not to affect texture color
|
||||
// Because Maya set diffuse color Kd to black when you use a diffuse color map
|
||||
|
@ -465,6 +460,7 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
|
|||
currMaterial->Meshbuffer->Material.DiffuseColor.set(
|
||||
currMaterial->Meshbuffer->Material.DiffuseColor.getAlpha(), 255, 255, 255 );
|
||||
}
|
||||
}
|
||||
return bufPtr;
|
||||
}
|
||||
|
||||
|
@ -491,7 +487,6 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
|
|||
if ( getMeshTextureLoader() )
|
||||
{
|
||||
getMeshTextureLoader()->setMaterialFile(mtlReader);
|
||||
getMeshTextureLoader()->setCheckForCachedTextures(true);
|
||||
getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(OBJ_TEXTURE_PATH));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue