From a6eafa79e278057ba33d2e13737cecbd91094f70 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 4 Nov 2002 09:08:50 +0000 Subject: [PATCH] From Ulrich Hertlien, added ReaderWriter::Options to the osgconv and pfb plugin so that all the pfi files can be converted to rgb be the plugin. --- include/osg/GeoSet | 2 +- include/osg/Shape | 2 +- src/Demos/osgconv/osgconv.cpp | 27 ++++++++++++++++++-- src/osgPlugins/pfb/ConvertFromPerformer.cpp | 28 ++++++++++++++++----- src/osgPlugins/pfb/ReaderWriterPFB.cpp | 22 ++++++++++------ 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/include/osg/GeoSet b/include/osg/GeoSet index 8e2d53e10..53a36137c 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -169,7 +169,7 @@ class SG_EXPORT GeoSet : public Drawable // data access methods. - inline void setNumPrims( int n ) { _numprims = n; } + inline void setNumPrims( int n ) { _numprims = n; _numcoords=0;} inline int getNumPrims() const { return _numprims; } void setPrimType( PrimitiveType type ); diff --git a/include/osg/Shape b/include/osg/Shape index 7b39ce2ce..46fdf9633 100644 --- a/include/osg/Shape +++ b/include/osg/Shape @@ -408,7 +408,7 @@ class SG_EXPORT HeightField : public Shape virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* libraryName() const { return "osg"; } - virtual const char* className() const { return "HeightFiled"; } + virtual const char* className() const { return "HeightField"; } virtual void accept(osg::ShapeVisitor& sv) { sv.apply(*this); } virtual void accept(osg::ConstShapeVisitor& csv) const { csv.apply(*this); } diff --git a/src/Demos/osgconv/osgconv.cpp b/src/Demos/osgconv/osgconv.cpp index 2a637ce3e..55c4cfd03 100644 --- a/src/Demos/osgconv/osgconv.cpp +++ b/src/Demos/osgconv/osgconv.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "OrientationConverter.h" @@ -23,6 +24,7 @@ static void usage( const char *prog, const char *msg ) osg::notify(osg::NOTICE)<<" " << prog << " [options] infile1 [infile2 ...] outfile"<< std::endl; osg::notify(osg::NOTICE)<< std::endl; osg::notify(osg::NOTICE)<<"options:"<< std::endl; + osg::notify(osg::NOTICE)<<" -O option - ReaderWriter option"<< std::endl; osg::notify(osg::NOTICE)<<" -l libraryName - load plugin of name libraryName"<< std::endl; osg::notify(osg::NOTICE)<<" i.e. -l osgdb_pfb"<< std::endl; osg::notify(osg::NOTICE)<<" Useful for loading reader/writers which can load"<< std::endl; @@ -66,9 +68,11 @@ static void usage( const char *prog, const char *msg ) } static bool -parse_args( int argc, char **argv, FileNameList &fileNames, OrientationConverter &oc ) +parse_args( int argc, char **argv, FileNameList &fileNames, + OrientationConverter &oc, osgDB::ReaderWriter::Options* options ) { int nexti; + string opt = ""; for(int i = 1; i < argc; i=nexti ) { @@ -80,6 +84,19 @@ parse_args( int argc, char **argv, FileNameList &fileNames, OrientationConverter { switch(argv[i][j]) { + case 'O': + if (nextisetOptionString(opt); + return true; } @@ -196,7 +216,10 @@ int main( int argc, char **argv ) FileNameList fileNames; OrientationConverter oc; - if( parse_args( argc, argv, fileNames, oc ) == false ) + osgDB::ReaderWriter::Options* options = new osgDB::ReaderWriter::Options; + osgDB::Registry::instance()->setOptions(options); + + if( parse_args( argc, argv, fileNames, oc, options ) == false ) return -1; std::string fileNameOut("converted.osg"); diff --git a/src/osgPlugins/pfb/ConvertFromPerformer.cpp b/src/osgPlugins/pfb/ConvertFromPerformer.cpp index 09d3ac77c..9175628bd 100644 --- a/src/osgPlugins/pfb/ConvertFromPerformer.cpp +++ b/src/osgPlugins/pfb/ConvertFromPerformer.cpp @@ -77,7 +77,6 @@ ConvertFromPerformer::ConvertFromPerformer() _saveImagesAsRGB = false; _saveAbsoluteImagePath = false; - } @@ -287,6 +286,7 @@ osg::Node* ConvertFromPerformer::visitSequence(osg::Group* osgParent, // add children for(int i=0;igetNumChildren();++i) { + //cerr << "child " << i << " time " << sequence->getTime(i) << endl; osgSequence->setTime(i, sequence->getTime(i)); visitNode(osgSequence,sequence->getChild(i)); } @@ -295,6 +295,7 @@ osg::Node* ConvertFromPerformer::visitSequence(osg::Group* osgParent, int mode, begin, end; sequence->getInterval(&mode, &begin, &end); + //cerr << "loop " << mode << endl; osg::Sequence::LoopMode loopMode = osg::Sequence::LOOP; if (mode == PFSEQ_SWING) loopMode = osg::Sequence::SWING; @@ -1164,7 +1165,6 @@ osg::Texture2D* ConvertFromPerformer::visitTexture(osg::StateSet* osgStateSet,pf osgTexture = new osg::Texture2D; registerPfObjectForOsgObject(tex, osgTexture); - //_pfToOsgMap[tex] = osgTexture; if (osgStateSet) osgStateSet->setTextureAttribute(0,osgTexture); @@ -1200,11 +1200,27 @@ osg::Texture2D* ConvertFromPerformer::visitTexture(osg::StateSet* osgStateSet,pf // image std::string texName = tex->getName(); - if (_saveImagesAsRGB) - { + if (_saveImagesAsRGB) { std::string strippedName = osgDB::getStrippedName(texName); - texName = _saveImageDirectory+strippedName+".rgb"; - tex->saveFile(texName.c_str()); + + pfList* imgList = tex->getList(); + if (imgList) { + // save image list + char buf[8]; + for (int i = 0; i < imgList->getNum(); i++) { + pfTexture* t = (pfTexture*) imgList->get(i); + if (t) { + snprintf(buf, sizeof(buf)-1, "_%04d", i); + texName = _saveImageDirectory+strippedName+buf+".rgb"; + t->saveFile(texName.c_str()); + } + } + } + else { + // save single image + texName = _saveImageDirectory+strippedName+".rgb"; + tex->saveFile(texName.c_str()); + } } if (!_saveAbsoluteImagePath) texName = osgDB::getSimpleFileName(texName); diff --git a/src/osgPlugins/pfb/ReaderWriterPFB.cpp b/src/osgPlugins/pfb/ReaderWriterPFB.cpp index bc04be2dd..5be7b2140 100644 --- a/src/osgPlugins/pfb/ReaderWriterPFB.cpp +++ b/src/osgPlugins/pfb/ReaderWriterPFB.cpp @@ -97,8 +97,7 @@ class ReaderWriterPFB : public osgDB::ReaderWriter virtual ReadResult readImage(const std::string& fileName, const osgDB::ReaderWriter::Options*) { - osg::notify(osg::INFO)<< "ReaderWriterPFB::readImage( "<ref(); ConvertFromPerformer converter; + if (options) { + const string option = options->getOptionString(); + if (option.find("saveImagesAsRGB") != string::npos) + converter.setSaveImagesAsRGB(true); + if (option.find("saveAbsoluteImagePath") != string::npos) + converter.setSaveAbsoluteImagePath(true); + } + + root->ref(); osg::Node* node = converter.convert(root); root->unrefDelete(); return node; @@ -178,9 +184,9 @@ class ReaderWriterPFB : public osgDB::ReaderWriter std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; - - osg::notify(osg::INFO)<< "ReaderWriterPFB::writeNode( "<