From 66ed3a919a7485c00da442973eae60c29d9b102c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 11 Apr 2008 10:16:38 +0000 Subject: [PATCH] From Bob Kuehne, "1) add simplifier command "--simplifier .5" to reduce complexity 2) complementarily add a "--overallNormal" to replace per-vert/per-facet normals with an overall. simplifier doesn't work in certain cases without less complex normals. this gets that done. 3) add env var output with full verbose output so people realize it's active when the app is run - i see this all the time in training where people run osgconv, with unintended data transformations due to osgUtil:;Optimzer, for example" --- applications/osgconv/osgconv.cpp | 88 +++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/applications/osgconv/osgconv.cpp b/applications/osgconv/osgconv.cpp index 3c97e1a9c..050c6663e 100644 --- a/applications/osgconv/osgconv.cpp +++ b/applications/osgconv/osgconv.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include +#include #include #include @@ -74,6 +76,37 @@ class MyGraphicsContext { osg::ref_ptr _gc; }; +class DefaultNormalsGeometryVisitor + : public osg::NodeVisitor +{ +public: + + DefaultNormalsGeometryVisitor() + : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ) { + } + + virtual void apply( osg::Geode & geode ) + { + for( unsigned int ii = 0; ii < geode.getNumDrawables(); ++ii ) + { + osg::ref_ptr< osg::Geometry > geometry = dynamic_cast< osg::Geometry * >( geode.getDrawable( ii ) ); + if( geometry.valid() ) + { + osg::ref_ptr< osg::Vec3Array > newnormals = new osg::Vec3Array; + newnormals->push_back( osg::Z_AXIS ); + geometry->setNormalArray( newnormals.get() ); + geometry->setNormalBinding( osg::Geometry::BIND_OVERALL ); + } + } + } + + virtual void apply( osg::Node & node ) + { + traverse( node ); + } + +}; + class CompressTexturesVisitor : public osg::NodeVisitor { public: @@ -369,10 +402,21 @@ static void usage( const char *prog, const char *msg ) osg::notify(osg::NOTICE)<< std::endl; osg::notify(osg::NOTICE) << msg << std::endl; } + + // basic usage osg::notify(osg::NOTICE)<< std::endl; osg::notify(osg::NOTICE)<<"usage:"<< std::endl; osg::notify(osg::NOTICE)<<" " << prog << " [options] infile1 [infile2 ...] outfile"<< std::endl; osg::notify(osg::NOTICE)<< std::endl; + + // print env options - especially since optimizer is always _on_ + osg::notify(osg::NOTICE)<<"environment:" << std::endl; + osg::ApplicationUsage::UsageMap um = osg::ApplicationUsage::instance()->getEnvironmentalVariables(); + std::string envstring; + osg::ApplicationUsage::instance()->getFormattedString( envstring, um ); + osg::notify(osg::NOTICE)<accept( dngv ); + } + + // apply any user-specified simplification + if ( do_simplify ) + { + osgUtil::Simplifier simple; + simple.setSmoothing( smooth ); + osg::notify( osg::ALWAYS ) << " smoothing: " << smooth << std::endl; + simple.setSampleRatio( simplifyPercent ); + root->accept( simple ); + } + osgDB::ReaderWriter::WriteResult result = osgDB::Registry::instance()->writeNode(*root,fileNameOut,osgDB::Registry::instance()->getOptions()); if (result.success()) {