Changeset 8074
- Timestamp:
- 04/11/08 12:16:38
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/applications/osgconv/osgconv.cpp
r7648 r8074 6 6 #include <osg/Notify> 7 7 #include <osg/Vec3> 8 #include <osg/ProxyNode> 8 9 #include <osg/Geometry> 9 10 #include <osg/Texture2D> … … 19 20 20 21 #include <osgUtil/Optimizer> 22 #include <osgUtil/Simplifier> 21 23 #include <osgUtil/SmoothingVisitor> 22 24 … … 73 75 private: 74 76 osg::ref_ptr<osg::GraphicsContext> _gc; 77 }; 78 79 class DefaultNormalsGeometryVisitor 80 : public osg::NodeVisitor 81 { 82 public: 83 84 DefaultNormalsGeometryVisitor() 85 : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ) { 86 } 87 88 virtual void apply( osg::Geode & geode ) 89 { 90 for( unsigned int ii = 0; ii < geode.getNumDrawables(); ++ii ) 91 { 92 osg::ref_ptr< osg::Geometry > geometry = dynamic_cast< osg::Geometry * >( geode.getDrawable( ii ) ); 93 if( geometry.valid() ) 94 { 95 osg::ref_ptr< osg::Vec3Array > newnormals = new osg::Vec3Array; 96 newnormals->push_back( osg::Z_AXIS ); 97 geometry->setNormalArray( newnormals.get() ); 98 geometry->setNormalBinding( osg::Geometry::BIND_OVERALL ); 99 } 100 } 101 } 102 103 virtual void apply( osg::Node & node ) 104 { 105 traverse( node ); 106 } 107 75 108 }; 76 109 … … 370 403 osg::notify(osg::NOTICE) << msg << std::endl; 371 404 } 405 406 // basic usage 372 407 osg::notify(osg::NOTICE)<< std::endl; 373 408 osg::notify(osg::NOTICE)<<"usage:"<< std::endl; 374 409 osg::notify(osg::NOTICE)<<" " << prog << " [options] infile1 [infile2 ...] outfile"<< std::endl; 375 410 osg::notify(osg::NOTICE)<< std::endl; 411 412 // print env options - especially since optimizer is always _on_ 413 osg::notify(osg::NOTICE)<<"environment:" << std::endl; 414 osg::ApplicationUsage::UsageMap um = osg::ApplicationUsage::instance()->getEnvironmentalVariables(); 415 std::string envstring; 416 osg::ApplicationUsage::instance()->getFormattedString( envstring, um ); 417 osg::notify(osg::NOTICE)<<envstring << std::endl; 418 419 // print tool options 376 420 osg::notify(osg::NOTICE)<<"options:"<< std::endl; 377 421 osg::notify(osg::NOTICE)<<" -O option - ReaderWriter option"<< std::endl; … … 431 475 " absolute position in world space\n" 432 476 << std::endl; 477 osg::notify(osg::NOTICE)<<" --simplify n - Run simplifier on prior to output. Argument must be a" << std::endl 478 <<" normalized value for the resultant percentage reduction." << std::endl 479 <<" Example: --simplify .5 will produce an 50 reduced model." << std::endl 480 << std::endl; 433 481 osg::notify(osg::NOTICE)<<" -s scale - Scale size of model. Scale argument must be the \n" 434 482 " following :\n" … … 443 491 osg::notify(osg::NOTICE)<<" --addMissingColors - Adding a white color value to all geometry that don't have\n" 444 492 " their own color values (--addMissingColours also accepted)."<< std::endl; 493 osg::notify(osg::NOTICE)<<" --overallNormal - Replace normals with a single overall normal."<< std::endl; 445 494 446 495 } … … 548 597 } 549 598 599 float simplifyPercent = 1.0; 600 bool do_simplify = false; 601 while ( arguments.read( "--simplify",str ) ) 602 { 603 float nsimp = 1.0; 604 if( sscanf( str.c_str(), "%f", 605 &nsimp ) != 1 ) 606 { 607 usage( argv[0], "Scale argument format incorrect." ); 608 return 1; 609 } 610 std::cout << str << " " << nsimp << std::endl; 611 simplifyPercent = nsimp; 612 osg::notify( osg::INFO ) << "Simplifying with percentage: " << simplifyPercent << std::endl; 613 do_simplify = true; 614 } 615 550 616 while (arguments.read("-t",str)) 551 617 { … … 587 653 while(arguments.read("--addMissingColours") || arguments.read("--addMissingColors")) { addMissingColours = true; } 588 654 655 bool do_overallNormal = false; 656 while(arguments.read("--overallNormal") || arguments.read("--overallNormal")) { do_overallNormal = true; } 657 589 658 // any option left unread are converted into errors to write out later. 590 659 arguments.reportRemainingOptionsAsUnrecognized(); … … 672 741 } 673 742 } 674 743 744 // scrub normals 745 if ( do_overallNormal ) 746 { 747 DefaultNormalsGeometryVisitor dngv; 748 root->accept( dngv ); 749 } 750 751 // apply any user-specified simplification 752 if ( do_simplify ) 753 { 754 osgUtil::Simplifier simple; 755 simple.setSmoothing( smooth ); 756 osg::notify( osg::ALWAYS ) << " smoothing: " << smooth << std::endl; 757 simple.setSampleRatio( simplifyPercent ); 758 root->accept( simple ); 759 } 760 675 761 osgDB::ReaderWriter::WriteResult result = osgDB::Registry::instance()->writeNode(*root,fileNameOut,osgDB::Registry::instance()->getOptions()); 676 762 if (result.success())
