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