| 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 <osgViewer/Viewer> |
|---|
| 13 | |
|---|
| 14 | #include <osgUtil/Optimizer> |
|---|
| 15 | |
|---|
| 16 | int main( int argc, char **argv ) |
|---|
| 17 | { |
|---|
| 18 | |
|---|
| 19 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | osgViewer::Viewer viewer; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | osg::Node* loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 26 | if (!loadedModel) |
|---|
| 27 | { |
|---|
| 28 | osg::notify(osg::NOTICE)<<"Please specifiy a model filename on the command line."<<std::endl; |
|---|
| 29 | return 1; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | osg::Group* rootnode = new osg::Group; |
|---|
| 38 | |
|---|
| 39 | osg::Group* decorator = new osg::Group; |
|---|
| 40 | |
|---|
| 41 | rootnode->addChild(loadedModel); |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | rootnode->addChild(decorator); |
|---|
| 45 | |
|---|
| 46 | decorator->addChild(loadedModel); |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 53 | osg::PolygonOffset* polyoffset = new osg::PolygonOffset; |
|---|
| 54 | polyoffset->setFactor(-1.0f); |
|---|
| 55 | polyoffset->setUnits(-1.0f); |
|---|
| 56 | osg::PolygonMode* polymode = new osg::PolygonMode; |
|---|
| 57 | polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); |
|---|
| 58 | stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 59 | stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 60 | |
|---|
| 61 | #if 1 |
|---|
| 62 | osg::Material* material = new osg::Material; |
|---|
| 63 | stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 64 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| 65 | #else |
|---|
| 66 | |
|---|
| 67 | osg::Material* material = new osg::Material; |
|---|
| 68 | material->setColorMode(osg::Material::OFF); |
|---|
| 69 | |
|---|
| 70 | material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 71 | material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 72 | material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); |
|---|
| 73 | |
|---|
| 74 | material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f)); |
|---|
| 75 | stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 76 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 77 | #endif |
|---|
| 78 | |
|---|
| 79 | stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | decorator->setStateSet(stateset); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | osgUtil::Optimizer optimzer; |
|---|
| 91 | optimzer.optimize(rootnode); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | viewer.setSceneData( rootnode ); |
|---|
| 95 | |
|---|
| 96 | return viewer.run(); |
|---|
| 97 | } |
|---|