diff --git a/include/osg/PagedLOD b/include/osg/PagedLOD index e7355452b..00071e3f0 100644 --- a/include/osg/PagedLOD +++ b/include/osg/PagedLOD @@ -43,6 +43,15 @@ class SG_EXPORT PagedLOD : public LOD virtual bool removeChild(Node *child); + + + + /** Set the database path to prepend to children's filenames.*/ + void setDatabasePath(const std::string& path); + + /** Get the database path used to prepend to children's filenames.*/ + inline const std::string& getDatabasePath() const { return _databasePath; } + struct SG_EXPORT PerRangeData { @@ -57,7 +66,7 @@ class SG_EXPORT PagedLOD : public LOD }; typedef std::vector PerRangeDataList; - + void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; } const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; } unsigned int getNumFileNames() const { return _perRangeDataList.size(); } @@ -112,6 +121,8 @@ class SG_EXPORT PagedLOD : public LOD void expandPerRangeDataTo(unsigned int pos); + std::string _databasePath; + int _frameNumberOfLastTraversal; unsigned int _numChildrenThatCannotBeExpired; PerRangeDataList _perRangeDataList; diff --git a/include/osgDB/Input b/include/osgDB/Input index ecbfa9540..7d1a4ac56 100644 --- a/include/osgDB/Input +++ b/include/osgDB/Input @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -35,6 +36,9 @@ class OSGDB_EXPORT Input : public FieldReaderIterator Input(); virtual ~Input(); + + void setOptions(const ReaderWriter::Options* options) { _options = options; } + const ReaderWriter::Options* getOptions() const { return _options.get(); } virtual osg::Object* readObjectOfType(const osg::Object& compObj); virtual osg::Object* readObjectOfType(const basic_type_wrapper &btw); @@ -56,6 +60,8 @@ class OSGDB_EXPORT Input : public FieldReaderIterator typedef std::map< std::string, osg::ref_ptr > UniqueIDToObjectMapping; UniqueIDToObjectMapping _uniqueIDToObjectMap; + + osg::ref_ptr _options; }; diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index f3d858310..988599703 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -35,6 +35,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced virtual const char* className() = 0; virtual bool acceptsExtension(const std::string& /*extension*/) { return false; } + /** Options base class used for passing options into plugins to control their operation.*/ class Options : public osg::Referenced { public: @@ -42,14 +43,24 @@ class OSGDB_EXPORT ReaderWriter : public osg::Referenced Options() {} Options(const std::string& str):_str(str) {} + /** Set the general Options string.*/ void setOptionString(const std::string& str) { _str = str; } + + /** Get the general Options string.*/ const std::string& getOptionString() const { return _str; } + /** Set the database path to use a hint of where to look when loading models.*/ + void setDatabasePath(const std::string& str) { _databasePath = str; } + + /** Get the database path which is used a hint of where to look when loading models.*/ + const std::string& getDatabasePath() const { return _databasePath; } + protected: virtual ~Options() {} std::string _str; + std::string _databasePath; }; diff --git a/src/osg/PagedLOD.cpp b/src/osg/PagedLOD.cpp index f91b1b2c8..18c724647 100644 --- a/src/osg/PagedLOD.cpp +++ b/src/osg/PagedLOD.cpp @@ -39,6 +39,38 @@ PagedLOD::PagedLOD(const PagedLOD& plod,const CopyOp& copyop): { } +void PagedLOD::setDatabasePath(const std::string& path) +{ + _databasePath = path; + if (!_databasePath.empty()) + { + char& lastCharacter = _databasePath[_databasePath.size()-1]; + const char unixSlash = '/'; + const char winSlash = '\\'; + + // make sure the last character is the appropriate slash +#ifdef WIN32 + if (lastCharacter==unixSlash) + { + lastCharacter = winSlash; + } + else if (lastCharacter!=winSlash) + { + _databasePath += winSlash; + } +#else + if (lastCharacter==winSlash) + { + lastCharacter = unixSlash; + } + else if (lastCharacter!=unixSlash) + { + _databasePath += unixSlash; + } +#endif + } +} + void PagedLOD::traverse(NodeVisitor& nv) { @@ -98,7 +130,15 @@ void PagedLOD::traverse(NodeVisitor& nv) // modify the priority according to the child's priority offset and scale. priority = _perRangeDataList[numChildren]._priorityOffset + priority * _perRangeDataList[numChildren]._priorityScale; - nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp()); + if (_databasePath.empty()) + { + nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp()); + } + else + { + // prepend the databasePath to the childs filename. + nv.getDatabaseRequestHandler()->requestNodeFile(_databasePath+_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp()); + } } diff --git a/src/osgPlugins/ive/DataInputStream.h b/src/osgPlugins/ive/DataInputStream.h index 7b72d892c..81031372f 100644 --- a/src/osgPlugins/ive/DataInputStream.h +++ b/src/osgPlugins/ive/DataInputStream.h @@ -13,15 +13,17 @@ #include #include #include +#include +#include +#include + +#include #include "IveVersion.h" #include "DataTypeSize.h" #include "Exception.h" -#include -#include -#include namespace ive{ @@ -30,6 +32,10 @@ class DataInputStream{ public: DataInputStream(std::istream* istream); ~DataInputStream(); + + void setOptions(const osgDB::ReaderWriter::Options* options) { _options = options; } + const osgDB::ReaderWriter::Options* getOptions() const { return _options.get(); } + unsigned int getVersion(); bool readBool(); char readChar(); @@ -92,6 +98,8 @@ private: DrawableMap _drawableMap; ShapeMap _shapeMap; NodeMap _nodeMap; + + osg::ref_ptr _options; }; diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index f63da4d49..423c87f4d 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -32,7 +32,7 @@ class IVEReaderWriter : public ReaderWriter return readNode(istream,options); } - virtual ReadResult readNode(std::istream& fin, const Options*) + virtual ReadResult readNode(std::istream& fin, const Options* options) { #define IVE_CATCH_EXCEPTIONS #ifdef IVE_CATCH_EXCEPTIONS @@ -40,6 +40,7 @@ class IVEReaderWriter : public ReaderWriter #endif // Create datainputstream. ive::DataInputStream in(&fin); + in.setOptions(options); return in.readNode(); #ifdef IVE_CATCH_EXCEPTIONS diff --git a/src/osgPlugins/osg/ReaderWriterOSG.cpp b/src/osgPlugins/osg/ReaderWriterOSG.cpp index 00ab1d258..ffef9db89 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG.cpp @@ -43,11 +43,12 @@ class OSGReaderWriter : public ReaderWriter } - virtual ReadResult readNode(std::istream& fin, const Options*) + virtual ReadResult readNode(std::istream& fin, const Options* options) { Input fr; fr.attach(&fin); + fr.setOptions(options); typedef std::vector NodeList; NodeList nodeList;