#include #include #include #include #include #include #include #include #include #include #include "OrientationConverter.h" #include "GeoSet.h" typedef std::vector FileNameList; static bool do_convert = false; //////////////////////////////////////////////////////////////////////////// // Convert GeoSet To Geometry Visitor. //////////////////////////////////////////////////////////////////////////// /** ConvertGeoSetsToGeometryVisitor all the old GeoSet Drawables to the new Geometry Drawables.*/ class ConvertGeoSetsToGeometryVisitor : public osg::NodeVisitor { public: ConvertGeoSetsToGeometryVisitor():osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {} virtual void apply(osg::Geode& geode) { for(unsigned int i=0;i(geode.getDrawable(i)); if (geoset) { osg::Geometry* geom = geoset->convertToGeometry(); if (geom) { std::cout<<"Successfully converted GeoSet to Geometry"<createLibraryNameForExtension(argv[nexti++]); osgDB::Registry::instance()->loadLibrary(libName); } else { usage( argv[0], "Extension option requires an argument." ); return false; } break; case('l'): if (nextiloadLibrary(argv[nexti++]); } else { usage( argv[0], "Library option requires an argument." ); return false; } break; case 'o' : if( nexti < argc ) { osg::Vec3 from, to; if( sscanf( argv[nexti++], "%f,%f,%f-%f,%f,%f", &from[0], &from[1], &from[2], &to[0], &to[1], &to[2] ) != 6 ) { usage( argv[0], "Orientation argument format incorrect." ); return false; } oc.setRotation( from, to ); do_convert = true; } else { usage( argv[0], "Orientation conversion option requires an argument." ); return false; } break; case 't' : if( nexti < argc ) { osg::Vec3 trans(0,0,0); if( sscanf( argv[nexti++], "%f,%f,%f", &trans[0], &trans[1], &trans[2] ) != 3 ) { usage( argv[0], "Translation argument format incorrect." ); return false; } oc.setTranslation( trans ); do_convert = true; } else { usage( argv[0], "Translation conversion option requires an argument." ); return false; } break; case 's' : if( nexti < argc ) { osg::Vec3 scale(0,0,0); if( sscanf( argv[nexti++], "%f,%f,%f", &scale[0], &scale[1], &scale[2] ) != 3 ) { usage( argv[0], "Scale argument format incorrect." ); return false; } oc.setScale( scale ); do_convert = true; } else { usage( argv[0], "Scale conversion option requires an argument." ); return false; } break; default : std::string a = "Invalid option " ; a += "'"; a += argv[i][j] ; a += "'."; usage( argv[0], a.c_str() ); return false; break; } } } else { fileNames.push_back(argv[i]); } } if (fileNames.empty()) { usage( argv[0], "No files specified." ); return false; } options->setOptionString(opt); return true; } int main( int argc, char **argv ) { FileNameList fileNames; OrientationConverter oc; 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"); if (fileNames.size()>1) { fileNameOut = fileNames.back(); fileNames.pop_back(); } osg::ref_ptr root = osgDB::readNodeFiles(fileNames); // convert the old style GeoSet to Geometry ConvertGeoSetsToGeometryVisitor cgtg; root->accept(cgtg); // optimize the scene graph, remove rendundent nodes and state etc. osgUtil::Optimizer optimizer; optimizer.optimize(root.get()); if( do_convert ) root = oc.convert( root.get() ); if (root.valid()) { if (osgDB::writeNodeFile(*root,fileNameOut)) { osg::notify(osg::NOTICE)<<"Data written to '"<