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.
This commit is contained in:
parent
22c6fa1565
commit
a6eafa79e2
@ -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 );
|
||||
|
@ -408,7 +408,7 @@ class SG_EXPORT HeightField : public Shape
|
||||
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const HeightField*>(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); }
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
#include <osgDB/ReaderWriter>
|
||||
|
||||
#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 (nexti<argc) {
|
||||
if (opt.size() == 0)
|
||||
opt = argv[nexti++];
|
||||
else
|
||||
opt = opt+" "+argv[nexti++];
|
||||
}
|
||||
else {
|
||||
usage( argv[0], "ReaderWriter option requires an argument." );
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case('e'):
|
||||
if (nexti<argc)
|
||||
{
|
||||
@ -188,6 +205,9 @@ parse_args( int argc, char **argv, FileNameList &fileNames, OrientationConverter
|
||||
usage( argv[0], "No files specified." );
|
||||
return false;
|
||||
}
|
||||
|
||||
options->setOptionString(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");
|
||||
|
@ -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;i<sequence->getNumChildren();++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);
|
||||
|
@ -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( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
osg::notify(osg::INFO)<<"ReaderWriterPFB::readImage( "<<fileName.c_str()<<" )\n";
|
||||
initPerformer();
|
||||
|
||||
pfTexture* tex = new pfTexture;
|
||||
@ -148,20 +147,27 @@ class ReaderWriterPFB : public osgDB::ReaderWriter
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
}
|
||||
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options*)
|
||||
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options)
|
||||
{
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(fileName);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
osg::notify(osg::INFO)<< "ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";
|
||||
|
||||
osg::notify(osg::INFO)<<"ReaderWriterPFB::readNode( "<<fileName.c_str()<<" )\n";
|
||||
initPerformer();
|
||||
|
||||
pfNode* root = pfdLoadFile(fileName.c_str());
|
||||
if (root)
|
||||
{
|
||||
root->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( "<<fileName.c_str()<<" )\n";
|
||||
osg::notify(osg::INFO)<<"ReaderWriterPFB::writeNode( "<<fileName.c_str()<<" )\n";
|
||||
initPerformer();
|
||||
|
||||
ConvertToPerformer converter;
|
||||
pfNode* root = converter.convert(&node);
|
||||
if (root)
|
||||
|
Loading…
Reference in New Issue
Block a user