| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| [1697] | 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/Group> |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | #include <osg/Material> |
|---|
| 23 | #include <osg/PolygonOffset> |
|---|
| 24 | #include <osg/PolygonMode> |
|---|
| 25 | #include <osg/LineStipple> |
|---|
| 26 | |
|---|
| 27 | #include <osgDB/Registry> |
|---|
| 28 | #include <osgDB/ReadFile> |
|---|
| 29 | |
|---|
| [5954] | 30 | #include <osgViewer/Viewer> |
|---|
| [1697] | 31 | |
|---|
| 32 | #include <osgUtil/Optimizer> |
|---|
| 33 | |
|---|
| 34 | int main( int argc, char **argv ) |
|---|
| 35 | { |
|---|
| 36 | |
|---|
| 37 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 38 | |
|---|
| 39 | |
|---|
| [5954] | 40 | osgViewer::Viewer viewer; |
|---|
| [1697] | 41 | |
|---|
| 42 | |
|---|
| 43 | osg::Node* loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| [6916] | 44 | |
|---|
| 45 | |
|---|
| [12529] | 46 | if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osgt"); |
|---|
| [6916] | 47 | |
|---|
| [1697] | 48 | if (!loadedModel) |
|---|
| 49 | { |
|---|
| [5954] | 50 | osg::notify(osg::NOTICE)<<"Please specifiy a model filename on the command line."<<std::endl; |
|---|
| [1697] | 51 | return 1; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | osg::Group* rootnode = new osg::Group; |
|---|
| 60 | |
|---|
| 61 | osg::Group* decorator = new osg::Group; |
|---|
| 62 | |
|---|
| 63 | rootnode->addChild(loadedModel); |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | rootnode->addChild(decorator); |
|---|
| 67 | |
|---|
| 68 | decorator->addChild(loadedModel); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 75 | osg::PolygonOffset* polyoffset = new osg::PolygonOffset; |
|---|
| 76 | polyoffset->setFactor(-1.0f); |
|---|
| 77 | polyoffset->setUnits(-1.0f); |
|---|
| 78 | osg::PolygonMode* polymode = new osg::PolygonMode; |
|---|
| 79 | polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); |
|---|
| 80 | stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 81 | stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| [2907] | 82 | |
|---|
| 83 | #if 1 |
|---|
| 84 | osg::Material* material = new osg::Material; |
|---|
| 85 | stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| [1697] | 86 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| [2907] | 87 | #else |
|---|
| 88 | |
|---|
| 89 | osg::Material* material = new osg::Material; |
|---|
| 90 | material->setColorMode(osg::Material::OFF); |
|---|
| 91 | |
|---|
| 92 | material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 93 | material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 94 | material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 95 | |
|---|
| 96 | material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f)); |
|---|
| 97 | stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 98 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 99 | #endif |
|---|
| 100 | |
|---|
| [1697] | 101 | stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | decorator->setStateSet(stateset); |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | osgUtil::Optimizer optimzer; |
|---|
| 113 | optimzer.optimize(rootnode); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | viewer.setSceneData( rootnode ); |
|---|
| 117 | |
|---|
| [5954] | 118 | return viewer.run(); |
|---|
| [1697] | 119 | } |
|---|