| 1 | #include <osg/Geode> |
|---|
| 2 | #include <osg/Group> |
|---|
| 3 | #include <osg/Notify> |
|---|
| 4 | #include <osg/Material> |
|---|
| 5 | #include <osg/PolygonOffset> |
|---|
| 6 | #include <osg/PolygonMode> |
|---|
| 7 | #include <osg/LineStipple> |
|---|
| 8 | |
|---|
| 9 | #include <osgDB/Registry> |
|---|
| 10 | #include <osgDB/ReadFile> |
|---|
| 11 | |
|---|
| 12 | #include <osgProducer/Viewer> |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | |
|---|
| 16 | int main( int argc, char **argv ) |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 24 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | osgProducer::Viewer viewer(arguments); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 37 | { |
|---|
| 38 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 39 | return 1; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | if (arguments.errors()) |
|---|
| 47 | { |
|---|
| 48 | arguments.writeErrorMessages(std::cout); |
|---|
| 49 | return 1; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if (arguments.argc()<=1) |
|---|
| 53 | { |
|---|
| 54 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 55 | return 1; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | osg::Node* loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 60 | if (!loadedModel) |
|---|
| 61 | { |
|---|
| 62 | return 1; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | osg::Group* rootnode = new osg::Group; |
|---|
| 71 | |
|---|
| 72 | osg::Group* decorator = new osg::Group; |
|---|
| 73 | |
|---|
| 74 | rootnode->addChild(loadedModel); |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | rootnode->addChild(decorator); |
|---|
| 78 | |
|---|
| 79 | decorator->addChild(loadedModel); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 86 | osg::Material* material = new osg::Material; |
|---|
| 87 | osg::PolygonOffset* polyoffset = new osg::PolygonOffset; |
|---|
| 88 | polyoffset->setFactor(-1.0f); |
|---|
| 89 | polyoffset->setUnits(-1.0f); |
|---|
| 90 | osg::PolygonMode* polymode = new osg::PolygonMode; |
|---|
| 91 | polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); |
|---|
| 92 | stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 93 | stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 94 | stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 95 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| 96 | stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | decorator->setStateSet(stateset); |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | osgUtil::Optimizer optimzer; |
|---|
| 108 | optimzer.optimize(rootnode); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | viewer.setSceneData( rootnode ); |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | viewer.realize(Producer::CameraGroup::ThreadPerCamera); |
|---|
| 115 | |
|---|
| 116 | while( !viewer.done() ) |
|---|
| 117 | { |
|---|
| 118 | |
|---|
| 119 | viewer.sync(); |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | viewer.update(); |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | viewer.frame(); |
|---|
| 127 | |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.sync(); |
|---|
| 132 | |
|---|
| 133 | return 0; |
|---|
| 134 | } |
|---|