Commit 4d45ef2e authored by cutealien's avatar cutealien

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-e03cc46cb475
parent 359ae63b
...@@ -31,10 +31,6 @@ class IMeshTextureLoader : public virtual IReferenceCounted ...@@ -31,10 +31,6 @@ class IMeshTextureLoader : public virtual IReferenceCounted
{ {
public: public:
//! Constructor
IMeshTextureLoader() : CheckForCachedTextures(false)
{}
//! Destructor //! Destructor
virtual ~IMeshTextureLoader() {} virtual ~IMeshTextureLoader() {}
...@@ -51,13 +47,6 @@ public: ...@@ -51,13 +47,6 @@ public:
\return Pointer to the texture. Returns 0 if loading failed.*/ \return Pointer to the texture. Returns 0 if loading failed.*/
virtual irr::video::ITexture* getTexture(const irr::io::path& textureName) = 0; 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. //! Meshloaders will search paths relative to the meshFile.
/** Usually you do not have to use this method, it is used internally by IMeshLoader's. /** 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. */ Any values you set here will likely be overwritten internally. */
...@@ -67,25 +56,6 @@ public: ...@@ -67,25 +56,6 @@ public:
/** Usually you do not have to use this method, it is used internally by IMeshLoader's. /** 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. */ Any values you set here will likely be overwritten internally. */
virtual void setMaterialFile(const irr::io::IReadFile* materialFile) = 0; 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 ...@@ -12,7 +12,6 @@ CMeshTextureLoader::CMeshTextureLoader(irr::io::IFileSystem* fs, irr::video::IVi
, VideoDriver(driver) , VideoDriver(driver)
, MeshFile(0) , MeshFile(0)
, MaterialFile(0) , MaterialFile(0)
, WasRecentTextureCached(false)
{ {
} }
...@@ -29,12 +28,11 @@ const irr::io::path& CMeshTextureLoader::getTexturePath() const ...@@ -29,12 +28,11 @@ const irr::io::path& CMeshTextureLoader::getTexturePath() const
return TexturePath; return TexturePath;
} }
bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename, bool checkCache) bool CMeshTextureLoader::checkTextureName( const irr::io::path& filename)
{ {
if (FileSystem->existFile(filename)) if (FileSystem->existFile(filename))
{ {
TextureName = filename; TextureName = filename;
WasRecentTextureCached = checkCache && VideoDriver->findTexture(TextureName) != 0;
return true; return true;
} }
...@@ -51,20 +49,18 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur ...@@ -51,20 +49,18 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
irr::io::path simplifiedTexName(textureName); irr::io::path simplifiedTexName(textureName);
simplifiedTexName.replace(_IRR_TEXT('\\'),_IRR_TEXT('/')); simplifiedTexName.replace(_IRR_TEXT('\\'),_IRR_TEXT('/'));
bool checkCache = getCheckForCachedTextures();
// user defined texture path // user defined texture path
if ( !TexturePath.empty() ) if ( !TexturePath.empty() )
{ {
if ( checkTextureName(TexturePath + simplifiedTexName, checkCache) ) if ( checkTextureName(TexturePath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName), checkCache) ) if ( checkTextureName(TexturePath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
} }
// just the name itself // just the name itself
if ( checkTextureName(simplifiedTexName, checkCache) ) if ( checkTextureName(simplifiedTexName) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
// look in files relative to the folder of the meshfile // look in files relative to the folder of the meshfile
...@@ -77,10 +73,10 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur ...@@ -77,10 +73,10 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
} }
if ( !MeshPath.empty() ) if ( !MeshPath.empty() )
{ {
if ( checkTextureName(MeshPath + simplifiedTexName, checkCache) ) if ( checkTextureName(MeshPath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName), checkCache) ) if ( checkTextureName(MeshPath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
} }
} }
...@@ -95,28 +91,22 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur ...@@ -95,28 +91,22 @@ irr::video::ITexture* CMeshTextureLoader::getTexture(const irr::io::path& textur
} }
if ( !MaterialPath.empty() ) if ( !MaterialPath.empty() )
{ {
if ( checkTextureName(MaterialPath + simplifiedTexName, checkCache) ) if ( checkTextureName(MaterialPath + simplifiedTexName) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName), checkCache) ) if ( checkTextureName(MaterialPath + FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
} }
} }
// check current working directory // check current working directory
if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName), checkCache) ) if ( checkTextureName(FileSystem->getFileBasename(simplifiedTexName)) )
return VideoDriver->getTexture(TextureName); return VideoDriver->getTexture(TextureName);
TextureName = _IRR_TEXT(""); TextureName = _IRR_TEXT("");
return NULL; 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. //! Meshloaders will search paths relative to the meshFile.
void CMeshTextureLoader::setMeshFile(const irr::io::IReadFile* meshFile) void CMeshTextureLoader::setMeshFile(const irr::io::IReadFile* meshFile)
{ {
......
...@@ -35,13 +35,6 @@ public: ...@@ -35,13 +35,6 @@ public:
\return Pointer to the texture. Returns 0 if loading failed.*/ \return Pointer to the texture. Returns 0 if loading failed.*/
virtual irr::video::ITexture* getTexture(const irr::io::path& textureName) _IRR_OVERRIDE_; 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. //! Meshloaders will search paths relative to the meshFile.
/** Usually you do not have to use this method, it is used internally by IMeshLoader's. /** 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. */ Any values you set here will likely be overwritten internally. */
...@@ -68,7 +61,7 @@ protected: ...@@ -68,7 +61,7 @@ protected:
} }
// Save the texturename when it's a an existing file // 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: private:
irr::io::IFileSystem * FileSystem; irr::io::IFileSystem * FileSystem;
...@@ -79,7 +72,6 @@ private: ...@@ -79,7 +72,6 @@ private:
const irr::io::IReadFile* MaterialFile; const irr::io::IReadFile* MaterialFile;
irr::io::path MaterialPath; irr::io::path MaterialPath;
irr::io::path TextureName; irr::io::path TextureName;
bool WasRecentTextureCached;
}; };
} // end namespace scene } // end namespace scene
......
...@@ -429,41 +429,37 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf ...@@ -429,41 +429,37 @@ const c8* COBJMeshFileLoader::readTextures(const c8* bufPtr, const c8* const buf
currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP); currMaterial->Meshbuffer->Material.setFlag(video::EMF_TEXTURE_WRAP, video::ETC_CLAMP);
io::path texname(textureNameBuf); io::path texname(textureNameBuf);
video::ITexture * texture = 0;
bool newTexture=false;
if (texname.size() && getMeshTextureLoader()) if (texname.size() && getMeshTextureLoader())
{ {
texture = getMeshTextureLoader()->getTexture(texname); video::ITexture * texture = getMeshTextureLoader()->getTexture(texname);
newTexture = !getMeshTextureLoader()->wasRecentTextureInCache(); if ( texture )
}
if ( texture )
{
if (type==0)
currMaterial->Meshbuffer->Material.setTexture(0, texture);
else if (type==1)
{
if (newTexture)
SceneManager->getVideoDriver()->makeNormalMapTexture(texture, bumpiness);
currMaterial->Meshbuffer->Material.setTexture(1, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_PARALLAX_MAP_SOLID;
currMaterial->Meshbuffer->Material.MaterialTypeParam=0.035f;
}
else if (type==2)
{
currMaterial->Meshbuffer->Material.setTexture(0, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
}
else if (type==3)
{ {
// currMaterial->Meshbuffer->Material.Textures[1] = texture; if (type==0)
// currMaterial->Meshbuffer->Material.MaterialType=video::EMT_REFLECTION_2_LAYER; currMaterial->Meshbuffer->Material.setTexture(0, texture);
else if (type==1)
{
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;
currMaterial->Meshbuffer->Material.MaterialTypeParam=0.035f;
}
else if (type==2)
{
currMaterial->Meshbuffer->Material.setTexture(0, texture);
currMaterial->Meshbuffer->Material.MaterialType=video::EMT_TRANSPARENT_ADD_COLOR;
}
else if (type==3)
{
// 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
// But is this the right thing to do?
currMaterial->Meshbuffer->Material.DiffuseColor.set(
currMaterial->Meshbuffer->Material.DiffuseColor.getAlpha(), 255, 255, 255 );
} }
// 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
// But is this the right thing to do?
currMaterial->Meshbuffer->Material.DiffuseColor.set(
currMaterial->Meshbuffer->Material.DiffuseColor.getAlpha(), 255, 255, 255 );
} }
return bufPtr; return bufPtr;
} }
...@@ -491,7 +487,6 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath) ...@@ -491,7 +487,6 @@ void COBJMeshFileLoader::readMTL(const c8* fileName, const io::path& relPath)
if ( getMeshTextureLoader() ) if ( getMeshTextureLoader() )
{ {
getMeshTextureLoader()->setMaterialFile(mtlReader); getMeshTextureLoader()->setMaterialFile(mtlReader);
getMeshTextureLoader()->setCheckForCachedTextures(true);
getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(OBJ_TEXTURE_PATH)); getMeshTextureLoader()->setTexturePath(SceneManager->getParameters()->getAttributeAsString(OBJ_TEXTURE_PATH));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment