Moved plugins across to using ReaderWriter::Options* for search paths in addition
to standard osgDB::DataFilePaths
This commit is contained in:
@@ -26,7 +26,8 @@ FltFile::FltFile(
|
||||
TexturePool* pTexturePool,
|
||||
MaterialPool* pMaterialPool,
|
||||
LtPtAppearancePool* pLtPtAppearancePool,
|
||||
LtPtAnimationPool* pLtPtAnimationPool)
|
||||
LtPtAnimationPool* pLtPtAnimationPool,
|
||||
osgDB::ReaderWriter::Options* options)
|
||||
{
|
||||
_useTextureAlphaForTransparancyBinning = true;
|
||||
_doUnitsConversion = true;
|
||||
@@ -93,6 +94,8 @@ FltFile::FltFile(
|
||||
|
||||
// instances are always internally defined
|
||||
setInstancePool( new InstancePool );
|
||||
|
||||
_options = options;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,17 +157,12 @@ bool FltFile::readModel(const std::string& fileName)
|
||||
bool FltFile::readFile(const std::string& fileName)
|
||||
{
|
||||
|
||||
// havn't found file, look in OSGFILEPATH
|
||||
std::string foundFileName = osgDB::findDataFile(fileName, _options.get());
|
||||
if (foundFileName.empty()) return false;
|
||||
|
||||
FileInput fin;
|
||||
if (!fin.open(fileName))
|
||||
{
|
||||
// havn't found file, look in OSGFILEPATH
|
||||
std::string foundFileName = osgDB::findDataFile(fileName);
|
||||
|
||||
if (foundFileName.empty()) return false;
|
||||
if (!fin.open(foundFileName)) return false;
|
||||
}
|
||||
|
||||
osg::notify(osg::INFO) << "Loading " << fileName << " ... " << std::endl;
|
||||
if (!fin.open(foundFileName)) return false;
|
||||
|
||||
Record* pRec = fin.readCreateRecord(this);
|
||||
if (pRec == NULL)
|
||||
@@ -234,39 +232,63 @@ bool FltFile::readFile(const std::string& fileName)
|
||||
}
|
||||
}
|
||||
|
||||
#if REGISTER_FLT
|
||||
pExternalFltFile = Registry::instance()->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<osgDB::ReaderWriter::Options> 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"<<pushAndPopPath<<std::endl;
|
||||
|
||||
options->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<osgDB::ReaderWriter::Options> _options;
|
||||
|
||||
osg::ref_ptr<ColorPool> _colorPool;
|
||||
osg::ref_ptr<TexturePool> _texturePool;
|
||||
osg::ref_ptr<LightPool> _lightPool;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<osg::Image> image = osgDB::readImageFile(textureName);
|
||||
osg::ref_ptr<osg::Image> 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<osgDB::ReaderWriter::Options> oldOptions = osgDB::Registry::instance()->getOptions();
|
||||
|
||||
osgDB::Registry::instance()->setOptions(new osgDB::ReaderWriter::Options(options));
|
||||
textureAttrData = dynamic_cast<flt::AttrData*>(osgDB::readObjectFile(attrName));
|
||||
|
||||
// Changed this line to restore the old options
|
||||
osgDB::Registry::instance()->setOptions( oldOptions.get() ); // Restore options
|
||||
textureAttrData = dynamic_cast<flt::AttrData*>(osgDB::readObjectFile(attrName, options ? options : osgDB::Registry::instance()->getOptions() ));
|
||||
|
||||
// if not found create default StateSet for the AttrData
|
||||
if (textureAttrData == NULL)
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
#include <osg/Group>
|
||||
#include <osgSim/BlinkSequence>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#include "AttrData.h"
|
||||
|
||||
#include <string>
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<FltFile> 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<ReaderWriter::Options> local_options = options ?
|
||||
static_cast<ReaderWriter::Options*>(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();
|
||||
|
||||
@@ -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<osg::Texture2D*>(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<flt::AttrData *> (pTexturePool->getTexture((int)mt->data[l].texture,mtr->getFlightVersion()));
|
||||
flt::AttrData *textureAttrData = dynamic_cast<flt::AttrData *> (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;
|
||||
|
||||
Reference in New Issue
Block a user