diff --git a/include/IMeshTextureLoader.h b/include/IMeshTextureLoader.h index 19b2f205..92df7b0d 100644 --- a/include/IMeshTextureLoader.h +++ b/include/IMeshTextureLoader.h @@ -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; }; diff --git a/source/Irrlicht/CMeshTextureLoader.cpp b/source/Irrlicht/CMeshTextureLoader.cpp index e8becd0b..81aaaf52 100644 --- a/source/Irrlicht/CMeshTextureLoader.cpp +++ b/source/Irrlicht/CMeshTextureLoader.cpp @@ -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) { diff --git a/source/Irrlicht/CMeshTextureLoader.h b/source/Irrlicht/CMeshTextureLoader.h index 6428a1d3..dac4929e 100644 --- a/source/Irrlicht/CMeshTextureLoader.h +++ b/source/Irrlicht/CMeshTextureLoader.h @@ -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 diff --git a/source/Irrlicht/COBJMeshFileLoader.cpp b/source/Irrlicht/COBJMeshFileLoader.cpp index 6cffce9b..ebd56d92 100644 --- a/source/Irrlicht/COBJMeshFileLoader.cpp +++ b/source/Irrlicht/COBJMeshFileLoader.cpp @@ -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); io::path texname(textureNameBuf); - video::ITexture * texture = 0; - bool newTexture=false; if (texname.size() && getMeshTextureLoader()) { - texture = getMeshTextureLoader()->getTexture(texname); - newTexture = !getMeshTextureLoader()->wasRecentTextureInCache(); - - } - if ( texture ) - { - if (type==0) - currMaterial->Meshbuffer->Material.setTexture(0, texture); - else if (type==1) + video::ITexture * texture = getMeshTextureLoader()->getTexture(texname); + if ( texture ) { - 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; + if (type==0) + 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 ); } - 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 ); } 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)); }