diff --git a/src/osgPlugins/osgViewer/GNUmakefile b/src/osgPlugins/osgViewer/GNUmakefile new file mode 100644 index 000000000..6c2f58ba3 --- /dev/null +++ b/src/osgPlugins/osgViewer/GNUmakefile @@ -0,0 +1,14 @@ +TOPDIR = ../../.. +include $(TOPDIR)/Make/makedefs + +CXXFILES =\ + View.cpp\ + ReaderWriterOsgViewer.cpp\ + +LIBS += -losgViewer -losgUtil -losgDB -losg $(OTHER_LIBS) + +TARGET_BASENAME = osgViewer +include $(TOPDIR)/Make/cygwin_plugin_def +PLUGIN = $(PLUGIN_PREFIX)$(TARGET_BASENAME).$(PLUGIN_EXT) + +include $(TOPDIR)/Make/makerules diff --git a/src/osgPlugins/osgViewer/IO_View.cpp b/src/osgPlugins/osgViewer/IO_View.cpp new file mode 100644 index 000000000..0a36bdd5c --- /dev/null +++ b/src/osgPlugins/osgViewer/IO_View.cpp @@ -0,0 +1,59 @@ +#include + +#include +#include + +#include +#include +#include +#include + +bool View_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool View_writeLocalData(const osg::Object &obj, osgDB::Output &fw); + +osgDB::RegisterDotOsgWrapperProxy View_Proxy +( + new osgViewer::View, + "View", + "Object View", + View_readLocalData, + View_writeLocalData +); + +bool View_readLocalData(osg::Object &obj, osgDB::Input &fr) +{ + osgViewer::View& view = static_cast(obj); + bool itAdvanced = false; + + return itAdvanced; +} + +bool View_writeLocalData(const osg::Object &obj, osgDB::Output &fw) +{ + const osgViewer::View& view = static_cast(obj); + + if (view.getCamera()) + { + fw.writeObject(*view.getCamera()); + } + + if (view.getNumSlaves() != 0) + { + fw.indent()<<"Slaves {"< + +#include + +#include +#include +#include +#include +#include + +class ReaderWriterOsgViewer : public osgDB::ReaderWriter +{ +public: + ReaderWriterOsgViewer() { } + + virtual const char* className() const { return "osgViewer configuration loader"; } + + virtual bool acceptsExtension(const std::string& extension) const + { + return osgDB::equalCaseInsensitive( extension, "osgViewer" ) || osgDB::equalCaseInsensitive( extension, "view" ) ; + } + + + void setPrecision(osgDB::Output& fout, const osgDB::ReaderWriter::Options* options) const + { + if (options) + { + std::istringstream iss(options->getOptionString()); + std::string opt; + while (iss >> opt) + { + if(opt=="PRECISION" || opt=="precision") + { + int prec; + iss >> prec; + fout.precision(prec); + } + if (opt=="OutputTextureFiles") + { + fout.setOutputTextureFiles(true); + } + } + } + } + + + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const + { + std::string ext = osgDB::getLowerCaseFileExtension(file); + if( !acceptsExtension(ext) ) + return ReadResult::FILE_NOT_HANDLED; + + std::string fileName = osgDB::findDataFile( file, options ); + if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + + // code for setting up the database path so that internally referenced file are searched for on relative paths. + std::ifstream fin(fileName.c_str()); + if (fin) + { + return readObject(fin, options); + } + return 0L; + + } + + virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const + { + osgDB::Input fr; + fr.attach(&fin); + fr.setOptions(options); + + typedef std::vector< osg::ref_ptr > ViewList; + ViewList viewList; + + // load all nodes in file, placing them in a group. + while(!fr.eof()) + { + osg::ref_ptr object = fr.readObject(); + osgViewer::View* view = dynamic_cast(object.get()); + if (view) + { + viewList.push_back(view); + } + else fr.advanceOverCurrentFieldOrBlock(); + } + + if (viewList.empty()) + { + return ReadResult("No data loaded"); + } + else if (viewList.size()==1) + { + return viewList.front().get(); + } + else + { + osg::notify(osg::NOTICE)<<"Found multiple view's, just taking first"< g_readerWriter_OsgViewer_Proxy; +