| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include <osgDB/ReadFile> |
|---|
| 13 | #include <osgUtil/Optimizer> |
|---|
| 14 | #include <osg/CoordinateSystemNode> |
|---|
| 15 | |
|---|
| 16 | #include <osg/Switch> |
|---|
| 17 | #include <osgText/Text> |
|---|
| 18 | |
|---|
| 19 | #include <osgViewer/Viewer> |
|---|
| 20 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 21 | |
|---|
| 22 | #include <osgGA/TrackballManipulator> |
|---|
| 23 | #include <osgGA/FlightManipulator> |
|---|
| 24 | #include <osgGA/DriveManipulator> |
|---|
| 25 | #include <osgGA/KeySwitchMatrixManipulator> |
|---|
| 26 | #include <osgGA/StateSetManipulator> |
|---|
| 27 | #include <osgGA/AnimationPathManipulator> |
|---|
| 28 | #include <osgGA/TerrainManipulator> |
|---|
| 29 | #include <osgGA/SphericalManipulator> |
|---|
| 30 | |
|---|
| 31 | #include <iostream> |
|---|
| 32 | |
|---|
| 33 | int main(int argc, char** argv) |
|---|
| 34 | { |
|---|
| 35 | |
|---|
| 36 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 37 | |
|---|
| 38 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 39 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
|---|
| 40 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 41 | arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); |
|---|
| 42 | arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); |
|---|
| 43 | arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); |
|---|
| 44 | |
|---|
| 45 | osgViewer::Viewer viewer(arguments); |
|---|
| 46 | |
|---|
| 47 | unsigned int helpType = 0; |
|---|
| 48 | if ((helpType = arguments.readHelpType())) |
|---|
| 49 | { |
|---|
| 50 | arguments.getApplicationUsage()->write(std::cout, helpType); |
|---|
| 51 | return 1; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | if (arguments.errors()) |
|---|
| 56 | { |
|---|
| 57 | arguments.writeErrorMessages(std::cout); |
|---|
| 58 | return 1; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | #if 0 |
|---|
| 62 | if (arguments.argc()<=1) |
|---|
| 63 | { |
|---|
| 64 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 65 | return 1; |
|---|
| 66 | } |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | std::string url, username, password; |
|---|
| 70 | while(arguments.read("--login",url, username, password)) |
|---|
| 71 | { |
|---|
| 72 | if (!osgDB::Registry::instance()->getAuthenticationMap()) |
|---|
| 73 | { |
|---|
| 74 | osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); |
|---|
| 75 | osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( |
|---|
| 76 | url, |
|---|
| 77 | new osgDB::AuthenticationDetails(username, password) |
|---|
| 78 | ); |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | { |
|---|
| 84 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
|---|
| 85 | |
|---|
| 86 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
|---|
| 87 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
|---|
| 88 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
|---|
| 89 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
|---|
| 90 | keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() ); |
|---|
| 91 | |
|---|
| 92 | std::string pathfile; |
|---|
| 93 | char keyForAnimationPath = '6'; |
|---|
| 94 | while (arguments.read("-p",pathfile)) |
|---|
| 95 | { |
|---|
| 96 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
|---|
| 97 | if (apm || !apm->valid()) |
|---|
| 98 | { |
|---|
| 99 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
|---|
| 100 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
|---|
| 101 | keyswitchManipulator->selectMatrixManipulator(num); |
|---|
| 102 | ++keyForAnimationPath; |
|---|
| 103 | } |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | viewer.addEventHandler(new osgViewer::LODScaleHandler); |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | viewer.addEventHandler(new osgViewer::ScreenCaptureHandler); |
|---|
| 132 | |
|---|
| 133 | std::string file = "http://www.openscenegraph.org/data/earth_bayarea/earth.ive"; |
|---|
| 134 | |
|---|
| 135 | osgDB::FileCache* fileCache = osgDB::Registry::instance()->getFileCache(); |
|---|
| 136 | if (fileCache) |
|---|
| 137 | { |
|---|
| 138 | osg::notify(osg::NOTICE)<<"We have FileCache "<<fileCache<<std::endl; |
|---|
| 139 | fileCache->loadDatabaseRevisionsForFile(file); |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile(file); |
|---|
| 144 | if (!loadedModel) |
|---|
| 145 | { |
|---|
| 146 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 147 | return 1; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | if (arguments.errors()) |
|---|
| 155 | { |
|---|
| 156 | arguments.writeErrorMessages(std::cout); |
|---|
| 157 | return 1; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | osgUtil::Optimizer optimizer; |
|---|
| 162 | optimizer.optimize(loadedModel.get()); |
|---|
| 163 | |
|---|
| 164 | viewer.setSceneData( loadedModel.get() ); |
|---|
| 165 | |
|---|
| 166 | viewer.realize(); |
|---|
| 167 | |
|---|
| 168 | return viewer.run(); |
|---|
| 169 | |
|---|
| 170 | } |
|---|