From ce07879e2ef4cbdc28dbd391e58f35dde75e64de Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 22 Nov 2004 23:54:45 +0000 Subject: [PATCH] Moved plugins across to using ReaderWriter::Options* for search paths in addition to standard osgDB::DataFilePaths --- include/osgDB/FileUtils | 21 +---- src/osgDB/FileUtils.cpp | 53 ++++++++--- src/osgPlugins/3dc/ReaderWriter3DC.cpp | 4 +- src/osgPlugins/Inventor/ReaderWriterIV.cpp | 4 +- src/osgPlugins/ac3d/ac3d.cpp | 4 +- src/osgPlugins/bmp/ReaderWriterBMP.cpp | 4 +- src/osgPlugins/dds/ReaderWriterDDS.cpp | 2 +- .../directx/ReaderWriterDirectX.cpp | 2 +- src/osgPlugins/dw/ReaderWriterDW.cpp | 4 +- src/osgPlugins/flt/FltFile.cpp | 88 ++++++++++++------- src/osgPlugins/flt/FltFile.h | 9 +- src/osgPlugins/flt/Input.cpp | 10 +-- src/osgPlugins/flt/Pool.cpp | 17 +--- src/osgPlugins/flt/Pool.h | 4 +- src/osgPlugins/flt/ReaderWriterATTR.cpp | 4 +- src/osgPlugins/flt/ReaderWriterFLT.cpp | 9 +- src/osgPlugins/flt/flt2osg.cpp | 29 +----- .../freetype/ReaderWriterFreeType.cpp | 4 +- src/osgPlugins/gdal/ReaderWriterGDAL.cpp | 2 +- src/osgPlugins/geo/ReaderWriterGEO.cpp | 4 +- src/osgPlugins/gif/ReaderWriterGIF.cpp | 4 +- src/osgPlugins/ive/ReaderWriterIVE.cpp | 2 +- src/osgPlugins/jp2/ReaderWriterJP2.cpp | 2 +- src/osgPlugins/jpeg/ReaderWriterJPEG.cpp | 4 +- src/osgPlugins/lib3ds/ReaderWriter3DS.cpp | 68 ++++++++------ src/osgPlugins/logo/ReaderWriterLOGO.cpp | 4 +- src/osgPlugins/lwo/Converter.cpp | 4 +- src/osgPlugins/lwo/Converter.h | 4 +- src/osgPlugins/lwo/ReaderWriterLWO.cpp | 66 +++++++------- src/osgPlugins/lws/ReaderWriterLWS.cpp | 4 +- src/osgPlugins/lws/SceneLoader.cpp | 4 +- src/osgPlugins/lws/SceneLoader.h | 4 +- src/osgPlugins/md2/ReaderWriterMD2.cpp | 4 +- src/osgPlugins/mpeg/ReaderWriterMPEG.cpp | 4 +- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 10 +-- src/osgPlugins/obj/obj.cpp | 4 +- src/osgPlugins/obj/obj.h | 4 +- src/osgPlugins/osg/ReaderWriterOSG.cpp | 10 +-- src/osgPlugins/osga/ReaderWriterOSGA.cpp | 4 +- src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp | 9 +- src/osgPlugins/pfb/ReaderWriterPFB.cpp | 6 +- src/osgPlugins/pic/ReaderWriterPIC.cpp | 4 +- src/osgPlugins/png/ReaderWriterPNG.cpp | 4 +- src/osgPlugins/pnm/ReaderWriterPNM.cpp | 4 +- src/osgPlugins/rgb/ReaderWriterRGB.cpp | 4 +- src/osgPlugins/stl/ReaderWriterSTL.cpp | 4 +- src/osgPlugins/tga/ReaderWriterTGA.cpp | 4 +- src/osgPlugins/tgz/ReaderWriterTGZ.cpp | 22 ++++- src/osgPlugins/tiff/ReaderWriterTIFF.cpp | 4 +- src/osgPlugins/txp/ReaderWriterTXP.cpp | 2 +- src/osgPlugins/zip/ReaderWriterZIP.cpp | 9 +- 51 files changed, 301 insertions(+), 263 deletions(-) diff --git a/include/osgDB/FileUtils b/include/osgDB/FileUtils index 64d26ae27..fc83a7f05 100644 --- a/include/osgDB/FileUtils +++ b/include/osgDB/FileUtils @@ -82,26 +82,7 @@ extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,CaseSen /** Search for specified file in file system, checking first the database path set in the Options structure, then the DataFilePathList for possible paths, * returning the full path of the first valid file found, return an empty string if no string is found. */ -extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,ReaderWriter::Options* options, CaseSensitivity caseSensitivity=CASE_SENSITIVE); - -/** Convinience class for pushing a path on construction, and popping the path - * and destruction. This helps keep the addition of a path local to a block - * of code, even in the presence of exceptions.*/ - -class PushAndPopDataPath -{ - public: - PushAndPopDataPath(const std::string& path) - { - getDataFilePathList().push_front(path); - } - - ~PushAndPopDataPath() - { - getDataFilePathList().pop_front(); - } -}; - +extern OSGDB_EXPORT std::string findDataFile(const std::string& filename,const ReaderWriter::Options* options, CaseSensitivity caseSensitivity=CASE_SENSITIVE); inline void setLibraryFilePathList(const FilePathList& filepaths) { osgDB::Registry::instance()->setLibraryFilePathList(filepaths); } diff --git a/src/osgDB/FileUtils.cpp b/src/osgDB/FileUtils.cpp index 109de819d..f01e32333 100644 --- a/src/osgDB/FileUtils.cpp +++ b/src/osgDB/FileUtils.cpp @@ -171,17 +171,13 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis if (filename.empty()) return filename; - if(fileExists(filename)) - { - osg::notify(osg::DEBUG_INFO) << "FindFileInPath(" << filename << "): returning " << filename << std::endl; - return filename; - } for(FilePathList::const_iterator itr=filepath.begin(); itr!=filepath.end(); ++itr) { - std::string path = *itr + '/'+ filename; + osg::notify(osg::DEBUG_INFO) << "itr='" <<*itr<< "'\n"; + std::string path = itr->empty() ? filename : *itr + '/'+ filename; osg::notify(osg::DEBUG_INFO) << "FindFileInPath() : trying " << path << " ...\n"; if(fileExists(path)) { @@ -202,15 +198,22 @@ std::string osgDB::findFileInPath(const std::string& filename, const FilePathLis return std::string(); } + std::string osgDB::findDataFile(const std::string& filename,CaseSensitivity caseSensitivity) { return findDataFile(filename,static_cast(0),caseSensitivity); } -OSGDB_EXPORT std::string osgDB::findDataFile(const std::string& filename,ReaderWriter::Options* options, CaseSensitivity caseSensitivity) +OSGDB_EXPORT std::string osgDB::findDataFile(const std::string& filename,const ReaderWriter::Options* options, CaseSensitivity caseSensitivity) { if (filename.empty()) return filename; + if(fileExists(filename)) + { + osg::notify(osg::DEBUG_INFO) << "FindFileInPath(" << filename << "): returning " << filename << std::endl; + return filename; + } + std::string fileFound; if (options && !options->getDatabasePathList().empty()) @@ -220,16 +223,36 @@ OSGDB_EXPORT std::string osgDB::findDataFile(const std::string& filename,ReaderW } const FilePathList& filepath = Registry::instance()->getDataFilePathList(); - - fileFound = findFileInPath(filename, filepath,caseSensitivity); - if (!fileFound.empty()) return fileFound; + if (!filepath.empty()) + { + fileFound = findFileInPath(filename, filepath,caseSensitivity); + if (!fileFound.empty()) return fileFound; + } + // if a directory is included in the filename, get just the (simple) filename itself and try that std::string simpleFileName = getSimpleFileName(filename); if (simpleFileName!=filename) { - fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity); - if (!fileFound.empty()) return fileFound; + + if(fileExists(simpleFileName)) + { + osg::notify(osg::DEBUG_INFO) << "FindFileInPath(" << filename << "): returning " << filename << std::endl; + return simpleFileName; + } + + if (options && !options->getDatabasePathList().empty()) + { + fileFound = findFileInPath(simpleFileName, options->getDatabasePathList(), caseSensitivity); + if (!fileFound.empty()) return fileFound; + } + + if (!filepath.empty()) + { + fileFound = findFileInPath(simpleFileName, filepath,caseSensitivity); + if (!fileFound.empty()) return fileFound; + } + } // return empty string. @@ -247,6 +270,12 @@ std::string osgDB::findLibraryFile(const std::string& filename,CaseSensitivity c if (!fileFound.empty()) return fileFound; + if(fileExists(filename)) + { + osg::notify(osg::DEBUG_INFO) << "FindFileInPath(" << filename << "): returning " << filename << std::endl; + return filename; + } + // if a directory is included in the filename, get just the (simple) filename itself and try that std::string simpleFileName = getSimpleFileName(filename); if (simpleFileName!=filename) diff --git a/src/osgPlugins/3dc/ReaderWriter3DC.cpp b/src/osgPlugins/3dc/ReaderWriter3DC.cpp index 14a6a87e8..1886f3e70 100644 --- a/src/osgPlugins/3dc/ReaderWriter3DC.cpp +++ b/src/osgPlugins/3dc/ReaderWriter3DC.cpp @@ -23,12 +23,12 @@ class ReaderWriter3DC : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"asc"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; std::cout << "try to read file "<getFltFile(filename); + + #if REGISTER_FLT + bool registerFLT = true; + #else + bool registerFLT = false; + #endif + + pExternalFltFile = registerFLT ? Registry::instance()->getFltFile(filename) : NULL; + if (pExternalFltFile == NULL) { - //Path for Nested external references - std::string filePath = osgDB::getFilePath(filename); - std::string pushAndPopPath; - //If absolute path - if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || - (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) + osg::ref_ptr options = new osgDB::ReaderWriter::Options; + + if (_pFltFile->getOptions()) { - pushAndPopPath = filePath; + options = _pFltFile->getOptions(); } else { - osgDB::FilePathList fpl = osgDB::getDataFilePathList(); - pushAndPopPath = fpl.empty() ? "." : fpl.front(); - if(pushAndPopPath.empty()) pushAndPopPath = "."; - pushAndPopPath += "/" + filePath; - } - osgDB::PushAndPopDataPath tmpfile(pushAndPopPath); + options = new osgDB::ReaderWriter::Options; + + //Path for Nested external references + std::string filePath = osgDB::getFilePath(filename); + std::string pushAndPopPath; + //If absolute path + if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || + (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) + { + pushAndPopPath = filePath; + } + else + { + osgDB::FilePathList fpl = osgDB::getDataFilePathList(); + pushAndPopPath = fpl.empty() ? "." : fpl.front(); + pushAndPopPath += "/" + filePath; + } + char optionsString[256]; + sprintf(optionsString,"FLT_VER %d",rec.getFlightVersion()); + options->setOptionString(optionsString); + + osg::notify(osg::NOTICE)<<"Create local path"<getDatabasePathList().push_back(pushAndPopPath); + } pExternalFltFile = new FltFile( pColorPool, pTexturePool, pMaterialPool, - pLtPtAppearancePool, pLtPtAnimationPool ); + pLtPtAppearancePool, pLtPtAnimationPool, options.get() ); + + if (registerFLT) + { + Registry::instance()->addFltFile(filename, pExternalFltFile); + } + pExternalFltFile->readModel(filename); } - Registry::instance()->addFltFile(filename, pExternalFltFile); - #else - pExternalFltFile = new FltFile( pColorPool, pTexturePool, pMaterialPool, - pLtPtAppearancePool, pLtPtAnimationPool ); - pExternalFltFile->readModel(filename); - #endif + rec.setExternal(pExternalFltFile); } } diff --git a/src/osgPlugins/flt/FltFile.h b/src/osgPlugins/flt/FltFile.h index 3936df067..80f3306a0 100644 --- a/src/osgPlugins/flt/FltFile.h +++ b/src/osgPlugins/flt/FltFile.h @@ -25,7 +25,8 @@ class FltFile : public osg::Referenced TexturePool* pTexturePool = NULL, MaterialPool* pMaterialPool = NULL, LtPtAppearancePool* pLtPtAppearancePool = NULL, - LtPtAnimationPool* pLtPtAnimationPool = NULL); + LtPtAnimationPool* pLtPtAnimationPool = NULL, + osgDB::ReaderWriter::Options* options =NULL); virtual osg::Object* readObject(const std::string& fileName); virtual osg::Node* readNode(const std::string& fileName); @@ -72,6 +73,10 @@ class FltFile : public osg::Referenced int getFlightVersion() const; inline HeaderRecord* getHeaderRecord() { return _headerRecord.get(); } void getOrigin( double& latitude, double& longitude ) const; + + void setOptions(osgDB::ReaderWriter::Options* options) { _options = options; } + osgDB::ReaderWriter::Options* getOptions() { return _options.get(); } + const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); } protected: @@ -94,6 +99,8 @@ class FltFile : public osg::Referenced std::string _directory; + osg::ref_ptr _options; + osg::ref_ptr _colorPool; osg::ref_ptr _texturePool; osg::ref_ptr _lightPool; diff --git a/src/osgPlugins/flt/Input.cpp b/src/osgPlugins/flt/Input.cpp index 456680a3b..45d8021c7 100644 --- a/src/osgPlugins/flt/Input.cpp +++ b/src/osgPlugins/flt/Input.cpp @@ -54,15 +54,7 @@ bool FileInput::eof() bool FileInput::open(const std::string& fileName) { _file=::fopen( fileName.c_str(), "rb"); - if (_file == NULL) - { - // ok havn't found file, resort to using findFile... - std::string newFileName = osgDB::findDataFile(fileName); - - if (newFileName.empty()) return false; - _file=::fopen( newFileName.c_str(), "rb"); - if (_file == NULL) return false; - } + if (_file == NULL) return false; _eof = false; return true; } diff --git a/src/osgPlugins/flt/Pool.cpp b/src/osgPlugins/flt/Pool.cpp index f7b63e287..4e1386c22 100644 --- a/src/osgPlugins/flt/Pool.cpp +++ b/src/osgPlugins/flt/Pool.cpp @@ -113,7 +113,7 @@ ColorPool::ColorName* ColorPool::getColorName(int nIndex) //////////////////////////////////////////////////////////////////// -flt::AttrData* TexturePool::getTexture(int nIndex, int fltVersion) +flt::AttrData* TexturePool::getTexture(int nIndex, osgDB::ReaderWriter::Options* options) { TexturePaletteMap::iterator fitr = _textureMap.find(nIndex); if (fitr != _textureMap.end()) @@ -145,24 +145,13 @@ flt::AttrData* TexturePool::getTexture(int nIndex, int fltVersion) unsigned int unit = 0; // Read texture and attribute file - osg::ref_ptr image = osgDB::readImageFile(textureName); + osg::ref_ptr image = osgDB::readImageFile(textureName, options ? options : osgDB::Registry::instance()->getOptions()); if (image.valid()) { std::string attrName(textureName); attrName += ".attr"; - // Read attribute file - char options[256]; - sprintf(options,"FLT_VER %d",fltVersion); - - // Add this line to save the existing options - osg::ref_ptr oldOptions = osgDB::Registry::instance()->getOptions(); - - osgDB::Registry::instance()->setOptions(new osgDB::ReaderWriter::Options(options)); - textureAttrData = dynamic_cast(osgDB::readObjectFile(attrName)); - - // Changed this line to restore the old options - osgDB::Registry::instance()->setOptions( oldOptions.get() ); // Restore options + textureAttrData = dynamic_cast(osgDB::readObjectFile(attrName, options ? options : osgDB::Registry::instance()->getOptions() )); // if not found create default StateSet for the AttrData if (textureAttrData == NULL) diff --git a/src/osgPlugins/flt/Pool.h b/src/osgPlugins/flt/Pool.h index febfbeb1e..c07dd70cb 100644 --- a/src/osgPlugins/flt/Pool.h +++ b/src/osgPlugins/flt/Pool.h @@ -15,6 +15,8 @@ #include #include +#include + #include "AttrData.h" #include @@ -66,7 +68,7 @@ class TexturePool : public osg::Referenced TexturePool() {} - flt::AttrData* getTexture(int nIndex, int fltVersion); + flt::AttrData* getTexture(int nIndex, osgDB::ReaderWriter::Options* options); std::string* getTextureName(int nIndex); void addTexture(int nIndex, flt::AttrData* attrdata); void addTextureName(int nIndex, const std::string& name); diff --git a/src/osgPlugins/flt/ReaderWriterATTR.cpp b/src/osgPlugins/flt/ReaderWriterATTR.cpp index 688d7948e..f0c81a6e4 100644 --- a/src/osgPlugins/flt/ReaderWriterATTR.cpp +++ b/src/osgPlugins/flt/ReaderWriterATTR.cpp @@ -749,12 +749,12 @@ class ReaderWriterATTR : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"attr"); } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // options diff --git a/src/osgPlugins/flt/ReaderWriterFLT.cpp b/src/osgPlugins/flt/ReaderWriterFLT.cpp index 474c8095f..e2e144122 100644 --- a/src/osgPlugins/flt/ReaderWriterFLT.cpp +++ b/src/osgPlugins/flt/ReaderWriterFLT.cpp @@ -28,7 +28,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fil std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::ref_ptr read = new FltFile; @@ -54,8 +54,15 @@ osgDB::ReaderWriter::ReadResult ReaderWriterFLT::readNode(const std::string& fil read->setDesiredUnits( FltFile::ConvertToNauticalMiles ); osg::notify(osg::DEBUG_INFO) << "FltFile.getDesiredUnits()=" << read->getDesiredUnitsString() << std::endl; } + } + osg::ref_ptr local_options = options ? + static_cast(options->clone(osg::CopyOp(osg::CopyOp::SHALLOW_COPY))) : + new ReaderWriter::Options; + local_options->setDatabasePath(osgDB::getFilePath(fileName)); + read->setOptions(local_options.get()); + osg::Node* node = read->readNode(fileName); flt::Registry::instance()->clearObjectCache(); diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 5e73fb7f7..bd911e175 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -1541,7 +1541,7 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet if (pTexturePool) { int nIndex = (int)pSFace->iTexturePattern; - flt::AttrData *textureAttrData = pTexturePool->getTexture(nIndex,rec->getFlightVersion()); + flt::AttrData *textureAttrData = pTexturePool->getTexture(nIndex,rec->getFltFile()->getOptions()); osg::StateSet *textureStateSet; if (textureAttrData) @@ -1561,7 +1561,7 @@ void ConvertFromFLT::setTexture ( FaceRecord *rec, SFace *pSFace, osg::StateSet flt::AttrData *detailTextureAttrData = NULL; if (pSFace->iDetailTexturePattern != -1) { int nIndex2 = (int)pSFace->iDetailTexturePattern; - detailTextureAttrData = pTexturePool->getTexture(nIndex2,rec->getFlightVersion()); + detailTextureAttrData = pTexturePool->getTexture(nIndex2,rec->getFltFile()->getOptions()); if (detailTextureAttrData && detailTextureAttrData->stateset) { osg::Texture2D *detTexture = dynamic_cast(detailTextureAttrData->stateset->getTextureAttribute( 0, osg::StateAttribute::TEXTURE)); textureStateSet->setTextureAttributeAndModes(1,detTexture,osg::StateAttribute::ON); @@ -1679,9 +1679,9 @@ ConvertFromFLT::addMultiTexture( DynGeoSet* dgset, MultiTextureRecord* mtr ) } // Get the texture attribute data from the texture pool - flt::AttrData *textureAttrData = dynamic_cast (pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion())); + flt::AttrData *textureAttrData = dynamic_cast (pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFltFile()->getOptions())); - CERR << "pTexturePool->getTexture((int)mt->data[l].texture): " << pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()) << "\n"; + CERR << "pTexturePool->getTexture((int)mt->data[l].texture): " << pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFltFile()->getOptions()) << "\n"; if (!textureAttrData) { CERR << "unable to set up multi-texture layer." << std::endl; @@ -2424,27 +2424,6 @@ osg::Group* ConvertFromFLT::visitMatrix(osg::Group& osgParent, const osg::Group& osg::Group* ConvertFromFLT::visitExternal(osg::Group& osgParent, ExternalRecord* rec) { - // SExternalReference *pSExternal = (SExternalReference*)rec->getData(); - - std::string filePath = osgDB::getFilePath(rec->getFilename()); - std::string pushAndPopPath; - //If absolute path - if( (filePath.length()>0 && filePath.find_first_of("/\\")==0) || - (filePath.length()>2 && filePath.substr(1,1)==":" && filePath.find_first_of("/\\")==2) ) - { - pushAndPopPath = filePath; - } - else - { - osgDB::FilePathList fpl = osgDB::getDataFilePathList(); - pushAndPopPath = fpl.empty() ? "." : fpl.front(); - if(pushAndPopPath.empty()) pushAndPopPath = "."; - pushAndPopPath += "/" + filePath; - } - - osgDB::PushAndPopDataPath tmpfile(pushAndPopPath); - //osgDB::PushAndPopDataPath tmpfile(osgDB::getFilePath(rec->getFilename())); - FltFile* pFile = rec->getExternal(); osg::Group* external = NULL; diff --git a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp index d71ca6551..2566cae42 100644 --- a/src/osgPlugins/freetype/ReaderWriterFreeType.cpp +++ b/src/osgPlugins/freetype/ReaderWriterFreeType.cpp @@ -22,12 +22,12 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"fnt"); // Windows bitmap fonts } - virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osgText::Font* font = FreeTypeLibrary::instance()->getFont(fileName,0); diff --git a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp index b9ea4d524..78f92954f 100644 --- a/src/osgPlugins/gdal/ReaderWriterGDAL.cpp +++ b/src/osgPlugins/gdal/ReaderWriterGDAL.cpp @@ -30,7 +30,7 @@ class ReaderWriterGDAL : public osgDB::ReaderWriter osg::notify(osg::INFO) << "GDAL : " << file << std::endl; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; initGDAL(); diff --git a/src/osgPlugins/geo/ReaderWriterGEO.cpp b/src/osgPlugins/geo/ReaderWriterGEO.cpp index 232ee1a84..bfdae8863 100644 --- a/src/osgPlugins/geo/ReaderWriterGEO.cpp +++ b/src/osgPlugins/geo/ReaderWriterGEO.cpp @@ -400,12 +400,12 @@ class ReaderWriterGEO : public osgDB::ReaderWriter virtual ReadResult readObject(const std::string& fileName, const Options* opt) { return readNode(fileName,opt); } - virtual ReadResult readNode(const std::string& file, const Options*) + virtual ReadResult readNode(const std::string& file, const Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; std::ifstream fin(fileName.c_str(), std::ios::binary | std::ios::in ); diff --git a/src/osgPlugins/gif/ReaderWriterGIF.cpp b/src/osgPlugins/gif/ReaderWriterGIF.cpp index 933f3ab27..75d7de3c3 100644 --- a/src/osgPlugins/gif/ReaderWriterGIF.cpp +++ b/src/osgPlugins/gif/ReaderWriterGIF.cpp @@ -324,12 +324,12 @@ class ReaderWriterGIF : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"gif"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; unsigned char *imageData = NULL; diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index e961ee987..d5134d4a1 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -30,7 +30,7 @@ class IVEReaderWriter : public ReaderWriter std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // code for setting up the database path so that any paged diff --git a/src/osgPlugins/jp2/ReaderWriterJP2.cpp b/src/osgPlugins/jp2/ReaderWriterJP2.cpp index d40e7499d..b02b5e4f8 100644 --- a/src/osgPlugins/jp2/ReaderWriterJP2.cpp +++ b/src/osgPlugins/jp2/ReaderWriterJP2.cpp @@ -194,7 +194,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if(fileName.empty()) { // note from Robert, Dec03, I find returning a valid image when no diff --git a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp index a42d2e02d..9b75aeefe 100644 --- a/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp +++ b/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp @@ -434,12 +434,12 @@ class ReaderWriterJPEG : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"jpeg") || osgDB::equalCaseInsensitive(extension,"jpg"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; unsigned char *imageData = NULL; diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 90ff84da2..e9ec6fdad 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -84,7 +84,6 @@ class PrintVisitor : public NodeVisitor int _step; }; -typedef std::map StateSetMap; class ReaderWriter3DS : public osgDB::ReaderWriter { public: @@ -94,25 +93,32 @@ class ReaderWriter3DS : public osgDB::ReaderWriter virtual const char* className() const { return "3DS Auto Studio Reader"; } virtual bool acceptsExtension(const std::string& extension) { return osgDB::equalCaseInsensitive(extension,"3ds"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*); - - typedef std::vector FaceList; - typedef std::map GeoStateMap; + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options); protected: - osg::Texture2D* createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy); - osg::StateSet* createStateSet(Lib3dsMaterial *materials); - osg::Drawable* createDrawable(Lib3dsMesh *meshes,FaceList& faceList, Lib3dsMatrix* matrix); - std::string _directory; - bool _useSmoothingGroups; - bool _usePerVertexNormals; + class ReaderObject + { + public: + ReaderObject(); + + typedef std::map StateSetMap; + typedef std::vector FaceList; + typedef std::map GeoStateMap; - // MIKEC - osg::Node* processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix); - osg::Node* processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node); + osg::Texture2D* createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy, const osgDB::ReaderWriter::Options* options); + osg::StateSet* createStateSet(Lib3dsMaterial *materials, const osgDB::ReaderWriter::Options* options); + osg::Drawable* createDrawable(Lib3dsMesh *meshes,FaceList& faceList, Lib3dsMatrix* matrix); + std::string _directory; + bool _useSmoothingGroups; + bool _usePerVertexNormals; + + // MIKEC + osg::Node* processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix); + osg::Node* processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node); + }; }; // now register with Registry to instantiate the above @@ -120,6 +126,10 @@ class ReaderWriter3DS : public osgDB::ReaderWriter osgDB::RegisterReaderWriterProxy g_readerWriter_3DS_Proxy; ReaderWriter3DS::ReaderWriter3DS() +{ +} + +ReaderWriter3DS::ReaderObject::ReaderObject() { _useSmoothingGroups = true; _usePerVertexNormals = true; @@ -201,7 +211,7 @@ void print(Lib3dsNode *node, int level) { // Transforms points by matrix if 'matrix' is not NULL // Creates a Geode and Geometry (as parent,child) and adds the Geode to 'parent' parameter iff 'parent' is non-NULL // Returns ptr to the Geode -osg::Node* ReaderWriter3DS::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix) { +osg::Node* ReaderWriter3DS::ReaderObject::processMesh(StateSetMap& drawStateMap,osg::Group* parent,Lib3dsMesh* mesh, Lib3dsMatrix* matrix) { typedef std::vector FaceList; typedef std::map MaterialFaceMap; MaterialFaceMap materialFaceMap; @@ -286,7 +296,7 @@ How to cope with pivot points in 3ds (short version) Tranform the node by the node matrix, which does the orientation about the pivot point, (and currently) transforms the object back by a translation to the PP. */ -osg::Node* ReaderWriter3DS::processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node) { +osg::Node* ReaderWriter3DS::ReaderObject::processNode(StateSetMap drawStateMap,Lib3dsFile *f,Lib3dsNode *node) { osg::Group* group=NULL;// created on demand if we find we have children to group together @@ -406,13 +416,13 @@ osg::Node* ReaderWriter3DS::processNode(StateSetMap drawStateMap,Lib3dsFile *f,L } -osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; Lib3dsFile *f = lib3ds_file_load(fileName.c_str()); @@ -424,16 +434,18 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil // but is VERY necessary if you want to use pivot points... lib3ds_file_eval(f,0.0f); // second param is time 't' for animated files - _directory = osgDB::getFilePath(fileName); + ReaderObject reader; + + reader._directory = osgDB::getFilePath(fileName); osg::Group* group = new osg::Group; group->setName(fileName); - StateSetMap drawStateMap; + ReaderObject::StateSetMap drawStateMap; for (Lib3dsMaterial *mat=f->materials; mat; mat=mat->next) { - drawStateMap[mat->name] = createStateSet(mat); + drawStateMap[mat->name] = reader.createStateSet(mat, options); } /*{ @@ -463,11 +475,11 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil if (traverse_nodes) { // old method for (Lib3dsMesh *mesh=f->meshes; mesh; mesh=mesh->next) { - processMesh(drawStateMap,group,mesh,NULL); + reader.processMesh(drawStateMap,group,mesh,NULL); } } else { // new method for(Lib3dsNode *node=f->nodes; node; node=node->next) { - group->addChild(processNode(drawStateMap,f,node)); + group->addChild(reader.processNode(drawStateMap,f,node)); } } @@ -485,7 +497,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil /** use matrix to pretransform geometry, or NULL to do nothing */ -osg::Drawable* ReaderWriter3DS::createDrawable(Lib3dsMesh *m,FaceList& faceList,Lib3dsMatrix *matrix) +osg::Drawable* ReaderWriter3DS::ReaderObject::createDrawable(Lib3dsMesh *m,FaceList& faceList,Lib3dsMatrix *matrix) { osg::Geometry* geom = new osg::Geometry; @@ -636,7 +648,7 @@ osg::Drawable* ReaderWriter3DS::createDrawable(Lib3dsMesh *m,FaceList& faceLis } -osg::Texture2D* ReaderWriter3DS::createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy) +osg::Texture2D* ReaderWriter3DS::ReaderObject::createTexture(Lib3dsTextureMap *texture,const char* label,bool& transparancy, const osgDB::ReaderWriter::Options* options) { if (texture && *(texture->name)) { @@ -644,7 +656,7 @@ osg::Texture2D* ReaderWriter3DS::createTexture(Lib3dsTextureMap *texture,const if (fileName.empty()) { // file not found in .3ds file's directory, so we'll look in the datafile path list. - fileName = osgDB::findDataFile(texture->name,osgDB::CASE_INSENSITIVE); + fileName = osgDB::findDataFile(texture->name,options, osgDB::CASE_INSENSITIVE); } if (fileName.empty()) @@ -696,7 +708,7 @@ osg::Texture2D* ReaderWriter3DS::createTexture(Lib3dsTextureMap *texture,const } -osg::StateSet* ReaderWriter3DS::createStateSet(Lib3dsMaterial *mat) +osg::StateSet* ReaderWriter3DS::ReaderObject::createStateSet(Lib3dsMaterial *mat, const osgDB::ReaderWriter::Options* options) { if (mat==NULL) return NULL; @@ -722,7 +734,7 @@ osg::StateSet* ReaderWriter3DS::createStateSet(Lib3dsMaterial *mat) stateset->setAttribute(material); bool textureTransparancy=false; - osg::Texture2D* texture1_map = createTexture(&(mat->texture1_map),"texture1_map",textureTransparancy); + osg::Texture2D* texture1_map = createTexture(&(mat->texture1_map),"texture1_map",textureTransparancy, options); if (texture1_map) { stateset->setTextureAttributeAndModes(0,texture1_map,osg::StateAttribute::ON); diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index a1ab58d9d..6629216a3 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -191,12 +191,12 @@ public: return osgDB::equalCaseInsensitive(extension,"logo"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO)<< "ReaderWriterLOGO::readNode( "< #include +#include + #include namespace lwosg @@ -37,7 +39,7 @@ namespace lwosg osg::Group *convert(Object &obj); osg::Group *convert(const iff::Chunk_list &data); - osg::Group *convert(const std::string &filename); + osg::Group *convert(const std::string &filename, const osgDB::ReaderWriter::Options* options); inline osg::Group *get_root() { return root_.get(); } inline const osg::Group *get_root() const { return root_.get(); } diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index f06164977..5f36965fa 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -53,27 +53,27 @@ public: virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { - std::string ext = osgDB::getLowerCaseFileExtension(file); + std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; ReadResult result = readNode_LWO1(fileName,options); if (result.success()) return result; - if (!options || options->getOptionString() != "USE_OLD_READER") { - ReadResult result = readNode_LWO2(fileName, options); - if (result.success()) return result; - } + if (!options || options->getOptionString() != "USE_OLD_READER") { + ReadResult result = readNode_LWO2(fileName, options); + if (result.success()) return result; + } - return readNode_old_LWO2(fileName, options); + return readNode_old_LWO2(fileName, options); } - lwosg::Converter::Options parse_options(const Options *options) const; + lwosg::Converter::Options parse_options(const Options *options) const; virtual ReadResult readNode_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*); - virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*); + virtual ReadResult readNode_old_LWO2(const std::string& fileName, const osgDB::ReaderWriter::Options*); virtual ReadResult readNode_LWO1(const std::string& fileName, const osgDB::ReaderWriter::Options*); protected: @@ -84,25 +84,25 @@ protected: lwosg::Converter::Options ReaderWriterLWO::parse_options(const Options *options) const { - lwosg::Converter::Options conv_options; + lwosg::Converter::Options conv_options; - if (options) { - std::istringstream iss(options->getOptionString()); - std::string opt; - while (iss >> opt) { - if (opt == "FORCE_ARB_COMPRESSION") conv_options.force_arb_compression = true; - if (opt == "USE_OSGFX") conv_options.use_osgfx = true; - if (opt == "NO_LIGHTMODEL_ATTRIBUTE") conv_options.apply_light_model = false; - if (opt == "MAX_TEXTURE_UNITS") { - int n; - if (iss >> n) { - conv_options.max_tex_units = n; - } - } - } - } + if (options) { + std::istringstream iss(options->getOptionString()); + std::string opt; + while (iss >> opt) { + if (opt == "FORCE_ARB_COMPRESSION") conv_options.force_arb_compression = true; + if (opt == "USE_OSGFX") conv_options.use_osgfx = true; + if (opt == "NO_LIGHTMODEL_ATTRIBUTE") conv_options.apply_light_model = false; + if (opt == "MAX_TEXTURE_UNITS") { + int n; + if (iss >> n) { + conv_options.max_tex_units = n; + } + } + } + } - return conv_options; + return conv_options; } @@ -111,15 +111,15 @@ osgDB::RegisterReaderWriterProxy g_lwoReaderWriterProxy; osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO2(const std::string &fileName, const osgDB::ReaderWriter::Options *options) { - lwosg::Converter::Options conv_options = parse_options(options); + lwosg::Converter::Options conv_options = parse_options(options); - lwosg::Converter converter(conv_options); - osg::ref_ptr node = converter.convert(fileName); - if (node.valid()) { - return node.take(); - } + lwosg::Converter converter(conv_options); + osg::ref_ptr node = converter.convert(fileName, options); + if (node.valid()) { + return node.take(); + } - return ReadResult::FILE_NOT_HANDLED; + return ReadResult::FILE_NOT_HANDLED; } diff --git a/src/osgPlugins/lws/ReaderWriterLWS.cpp b/src/osgPlugins/lws/ReaderWriterLWS.cpp index 647253cb6..503cd1a80 100644 --- a/src/osgPlugins/lws/ReaderWriterLWS.cpp +++ b/src/osgPlugins/lws/ReaderWriterLWS.cpp @@ -36,13 +36,13 @@ public: std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile(file); + std::string fileName = osgDB::findDataFile(file, options); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; lwosg::SceneLoader::Options conv_options = parse_options(options); lwosg::SceneLoader scene_loader(conv_options); - osg::ref_ptr node = scene_loader.load(fileName); + osg::ref_ptr node = scene_loader.load(fileName, options); if (node.valid()) { return node.take(); } diff --git a/src/osgPlugins/lws/SceneLoader.cpp b/src/osgPlugins/lws/SceneLoader.cpp index bbb7ce778..78b48a369 100644 --- a/src/osgPlugins/lws/SceneLoader.cpp +++ b/src/osgPlugins/lws/SceneLoader.cpp @@ -80,12 +80,12 @@ SceneLoader::SceneLoader(const Options &options) { } -osg::Group *SceneLoader::load(const std::string &filename, bool search) +osg::Group *SceneLoader::load(const std::string &filename, const osgDB::ReaderWriter::Options *options, bool search) { std::string fname; if (search) { - fname = osgDB::findDataFile(filename); + fname = osgDB::findDataFile(filename, options); if (fname.empty()) return 0; } else { fname = filename; diff --git a/src/osgPlugins/lws/SceneLoader.h b/src/osgPlugins/lws/SceneLoader.h index a812df82f..be67367c4 100644 --- a/src/osgPlugins/lws/SceneLoader.h +++ b/src/osgPlugins/lws/SceneLoader.h @@ -14,6 +14,8 @@ #include #include +#include + #include #include #include @@ -60,7 +62,7 @@ namespace lwosg SceneLoader(); SceneLoader(const Options &options); - osg::Group *load(const std::string &filename, bool search = false); + osg::Group *load(const std::string &filename, const osgDB::ReaderWriter::Options *options, bool search = false); inline osg::Group *get_root() { return root_.get(); } inline const osg::Group *get_root() const { return root_.get(); } diff --git a/src/osgPlugins/md2/ReaderWriterMD2.cpp b/src/osgPlugins/md2/ReaderWriterMD2.cpp index 41b10eef4..35acbf87a 100644 --- a/src/osgPlugins/md2/ReaderWriterMD2.cpp +++ b/src/osgPlugins/md2/ReaderWriterMD2.cpp @@ -61,12 +61,12 @@ osgDB::RegisterReaderWriterProxy g_readerWriter_MD2_Proxy; osgDB::ReaderWriter::ReadResult ReaderWriterMD2::readNode (const std::string& file, - const osgDB::ReaderWriter::Options*) + const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string filename = osgDB::findDataFile( file ); + std::string filename = osgDB::findDataFile( file, options ); if (filename.empty()) return ReadResult::FILE_NOT_FOUND; return load_md2 (filename.data()); diff --git a/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp b/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp index 37d671295..1eee1b918 100644 --- a/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp +++ b/src/osgPlugins/mpeg/ReaderWriterMPEG.cpp @@ -21,12 +21,12 @@ class ReaderWriterMPEG : public osgDB::ReaderWriter osgDB::equalCaseInsensitive(extension,"mpv"); } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::MpegImageStream* mpeg = new osg::MpegImageStream(fileName.c_str()); diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index d3b5b41cf..bdd0dc4a7 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -446,12 +446,12 @@ osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model) // read file and convert to OSG. -osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; @@ -461,7 +461,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil obj::Model model; model.setDatabasePath(osgDB::getFilePath(fileName.c_str())); - model.readOBJ(fin); + model.readOBJ(fin, options); osg::Node* node = convertModelToSceneGraph(model); return node; @@ -470,12 +470,12 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil return ReadResult::FILE_NOT_HANDLED; } -osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options*) +osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(std::istream& fin, const Options* options) { if (fin) { obj::Model model; - model.readOBJ(fin); + model.readOBJ(fin, options); osg::Node* node = convertModelToSceneGraph(model); return node; diff --git a/src/osgPlugins/obj/obj.cpp b/src/osgPlugins/obj/obj.cpp index b8d22d88e..4983e9717 100644 --- a/src/osgPlugins/obj/obj.cpp +++ b/src/osgPlugins/obj/obj.cpp @@ -260,7 +260,7 @@ bool Model::readMTL(std::istream& fin) return true; } -bool Model::readOBJ(std::istream& fin) +bool Model::readOBJ(std::istream& fin, const osgDB::ReaderWriter::Options* options) { osg::notify(osg::INFO)<<"Reading OBJ file"< #include +#include + namespace obj { @@ -157,7 +159,7 @@ public: const std::string& getDatabasePath() const { return databasePath; } bool readMTL(std::istream& fin); - bool readOBJ(std::istream& fin); + bool readOBJ(std::istream& fin, const osgDB::ReaderWriter::Options* options); bool readline(std::istream& fin, char* line, const int LINE_SIZE); void addElement(Element* element); diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 27ebb895c..5733e2cfd 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -32,18 +32,14 @@ class OSGReaderWriter : public ReaderWriter std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, opt ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; // code for setting up the database path so that any paged // databases can be automatically located. - osg::ref_ptr local_opt = const_cast(opt); - if (!local_opt) local_opt = new Options; + osg::ref_ptr local_opt = opt ? static_cast(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; - if (local_opt.valid() && local_opt->getDatabasePathList().empty()) - { - local_opt->setDatabasePath(osgDB::getFilePath(fileName)); - } + local_opt->setDatabasePath(osgDB::getFilePath(fileName)); std::ifstream fin(fileName.c_str()); if (fin) diff --git a/src/osgPlugins/osga/ReaderWriterOSGA.cpp b/src/osgPlugins/osga/ReaderWriterOSGA.cpp index 28ad20942..f34934105 100644 --- a/src/osgPlugins/osga/ReaderWriterOSGA.cpp +++ b/src/osgPlugins/osga/ReaderWriterOSGA.cpp @@ -17,13 +17,13 @@ public: return osgDB::equalCaseInsensitive(extension,"osga"); } - virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* = NULL) + virtual ReadResult openArchive(const std::string& file,ArchiveStatus status, unsigned int indexBlockSize = 4096, const Options* options=NULL) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) { if (status==READ) return ReadResult::FILE_NOT_FOUND; diff --git a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp index 61b3d6215..ff9620ad2 100644 --- a/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp +++ b/src/osgPlugins/osgtgz/ReaderWriterOSGTGZ.cpp @@ -30,12 +30,12 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"osgtgz"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file,options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO)<<"sgReaderWriterOSGTGZ::readNode( "< local_options = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::ReaderWriter::Options; + local_options->getDatabasePathList().push_front(dirname); osgDB::DirectoryContents contents = osgDB::getDirectoryContents(dirname); for(osgDB::DirectoryContents::iterator itr = contents.begin(); @@ -85,7 +86,7 @@ class sgReaderWriterOSGTGZ : public osgDB::ReaderWriter std::string file_ext = osgDB::getLowerCaseFileExtension(*itr); if (osgDB::equalCaseInsensitive(file_ext,"osg")) { - osg::Node *node = osgDB::readNodeFile( *itr ); + osg::Node *node = osgDB::readNodeFile( *itr, local_options.get() ); grp->addChild( node ); } } diff --git a/src/osgPlugins/pfb/ReaderWriterPFB.cpp b/src/osgPlugins/pfb/ReaderWriterPFB.cpp index bcf67b354..62488cb7c 100644 --- a/src/osgPlugins/pfb/ReaderWriterPFB.cpp +++ b/src/osgPlugins/pfb/ReaderWriterPFB.cpp @@ -95,9 +95,9 @@ class ReaderWriterPFB : public osgDB::ReaderWriter false; } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) fileName = file; // let Peformer see if it can file the filep osg::notify(osg::INFO)<<"ReaderWriterPFB::readImage( "< local_options = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::ReaderWriter::Options; + local_options->getDatabasePathList().push_front(dirname); + + osg::notify(osg::NOTICE)<<"local_options->getDatabasePathList().="<getDatabasePathList().front()<addChild( node ); } } diff --git a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp index 695893c5d..9d9c1d559 100644 --- a/src/osgPlugins/tiff/ReaderWriterTIFF.cpp +++ b/src/osgPlugins/tiff/ReaderWriterTIFF.cpp @@ -420,12 +420,12 @@ class ReaderWriterTIFF : public osgDB::ReaderWriter return false; } - virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readImage(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; unsigned char *imageData = NULL; diff --git a/src/osgPlugins/txp/ReaderWriterTXP.cpp b/src/osgPlugins/txp/ReaderWriterTXP.cpp index 362f7520a..f4a586430 100644 --- a/src/osgPlugins/txp/ReaderWriterTXP.cpp +++ b/src/osgPlugins/txp/ReaderWriterTXP.cpp @@ -29,7 +29,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterTXP::readNode(const std::string& fil // We load archive.txp if (strncmp(name.c_str(),"archive",7)==0) { - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::ref_ptr txpNode = new TXPNode; diff --git a/src/osgPlugins/zip/ReaderWriterZIP.cpp b/src/osgPlugins/zip/ReaderWriterZIP.cpp index 182a998aa..2a09fdba3 100644 --- a/src/osgPlugins/zip/ReaderWriterZIP.cpp +++ b/src/osgPlugins/zip/ReaderWriterZIP.cpp @@ -29,13 +29,13 @@ class ReaderWriterZIP : public osgDB::ReaderWriter return osgDB::equalCaseInsensitive(extension,"zip"); } - virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options*) + virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) { std::string ext = osgDB::getLowerCaseFileExtension(file); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; - std::string fileName = osgDB::findDataFile( file ); + std::string fileName = osgDB::findDataFile( file, options ); if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; osg::notify(osg::INFO)<<"ReaderWriterZIP::readNode( "< local_options = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::ReaderWriter::Options; + local_options->getDatabasePathList().push_front(dirname); bool prevCreateNodeFromImage = osgDB::Registry::instance()->getCreateNodeFromImage(); osgDB::Registry::instance()->setCreateNodeFromImage(false); @@ -82,7 +83,7 @@ class ReaderWriterZIP : public osgDB::ReaderWriter *itr!=std::string(".") && *itr!=std::string("..")) { - osg::Node *node = osgDB::readNodeFile( *itr ); + osg::Node *node = osgDB::readNodeFile( *itr, local_options.get() ); grp->addChild( node ); } }