| 1 | #include <osg/MatrixTransform> |
|---|
| 2 | #include <osg/ClipNode> |
|---|
| 3 | #include <osg/Billboard> |
|---|
| 4 | #include <osg/Geode> |
|---|
| 5 | #include <osg/Group> |
|---|
| 6 | #include <osg/Notify> |
|---|
| 7 | #include <osg/Material> |
|---|
| 8 | #include <osg/PolygonOffset> |
|---|
| 9 | #include <osg/PolygonMode> |
|---|
| 10 | #include <osg/LineStipple> |
|---|
| 11 | #include <osg/AnimationPath> |
|---|
| 12 | |
|---|
| 13 | #include <osgDB/Registry> |
|---|
| 14 | #include <osgDB/ReadFile> |
|---|
| 15 | |
|---|
| 16 | #include <osgGA/TrackballManipulator> |
|---|
| 17 | #include <osgGA/FlightManipulator> |
|---|
| 18 | #include <osgGA/DriveManipulator> |
|---|
| 19 | |
|---|
| 20 | #include <osgViewer/Viewer> |
|---|
| 21 | |
|---|
| 22 | #include <osgUtil/Optimizer> |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | osg::Node* decorate_with_clip_node(osg::Node* subgraph) |
|---|
| 26 | { |
|---|
| 27 | osg::Group* rootnode = new osg::Group; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 33 | |
|---|
| 34 | osg::PolygonMode* polymode = new osg::PolygonMode; |
|---|
| 35 | polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); |
|---|
| 36 | stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 37 | |
|---|
| 38 | osg::Group* wireframe_subgraph = new osg::Group; |
|---|
| 39 | wireframe_subgraph->setStateSet(stateset); |
|---|
| 40 | wireframe_subgraph->addChild(subgraph); |
|---|
| 41 | rootnode->addChild(wireframe_subgraph); |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | osg::MatrixTransform* transform= new osg::MatrixTransform; |
|---|
| 67 | |
|---|
| 68 | osg::NodeCallback* nc = new osg::AnimationPathCallback(subgraph->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); |
|---|
| 69 | transform->setUpdateCallback(nc); |
|---|
| 70 | |
|---|
| 71 | osg::ClipNode* clipnode = new osg::ClipNode; |
|---|
| 72 | osg::BoundingSphere bs = subgraph->getBound(); |
|---|
| 73 | bs.radius()*= 0.4f; |
|---|
| 74 | |
|---|
| 75 | osg::BoundingBox bb; |
|---|
| 76 | bb.expandBy(bs); |
|---|
| 77 | |
|---|
| 78 | clipnode->createClipBox(bb); |
|---|
| 79 | clipnode->setCullingActive(false); |
|---|
| 80 | |
|---|
| 81 | transform->addChild(clipnode); |
|---|
| 82 | rootnode->addChild(transform); |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | osg::Group* clipped_subgraph = new osg::Group; |
|---|
| 87 | |
|---|
| 88 | clipped_subgraph->setStateSet(clipnode->getStateSet()); |
|---|
| 89 | clipped_subgraph->addChild(subgraph); |
|---|
| 90 | rootnode->addChild(clipped_subgraph); |
|---|
| 91 | |
|---|
| 92 | return rootnode; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | int main( int argc, char **argv ) |
|---|
| 97 | { |
|---|
| 98 | |
|---|
| 99 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | osg::Node* loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | if (!loadedModel) loadedModel = osgDB::readNodeFile("cow.osg"); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | if (!loadedModel) |
|---|
| 110 | { |
|---|
| 111 | osg::notify(osg::NOTICE)<<"Please specifiy a filename and the command line"<<std::endl; |
|---|
| 112 | return 1; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | osg::Node* rootnode = decorate_with_clip_node(loadedModel); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | osgUtil::Optimizer optimzer; |
|---|
| 120 | optimzer.optimize(rootnode); |
|---|
| 121 | |
|---|
| 122 | osgViewer::Viewer viewer; |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | viewer.setSceneData(rootnode); |
|---|
| 126 | |
|---|
| 127 | return viewer.run(); |
|---|
| 128 | } |
|---|