| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| [6751] | 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osgDB/ReadFile> |
|---|
| 20 | #include <osgUtil/Optimizer> |
|---|
| 21 | #include <osg/CoordinateSystemNode> |
|---|
| 22 | |
|---|
| 23 | #include <osg/Switch> |
|---|
| 24 | #include <osgText/Text> |
|---|
| 25 | |
|---|
| 26 | #include <osgViewer/Viewer> |
|---|
| 27 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 28 | |
|---|
| 29 | #include <osgGA/TrackballManipulator> |
|---|
| 30 | #include <osgGA/FlightManipulator> |
|---|
| 31 | #include <osgGA/DriveManipulator> |
|---|
| 32 | #include <osgGA/KeySwitchMatrixManipulator> |
|---|
| 33 | #include <osgGA/StateSetManipulator> |
|---|
| 34 | #include <osgGA/AnimationPathManipulator> |
|---|
| 35 | #include <osgGA/TerrainManipulator> |
|---|
| 36 | |
|---|
| 37 | #include <iostream> |
|---|
| 38 | |
|---|
| [6927] | 39 | |
|---|
| [10282] | 40 | USE_OSGPLUGIN(ive) |
|---|
| 41 | USE_OSGPLUGIN(osg) |
|---|
| [11912] | 42 | USE_OSGPLUGIN(osg2) |
|---|
| [10282] | 43 | USE_OSGPLUGIN(rgb) |
|---|
| 44 | USE_OSGPLUGIN(OpenFlight) |
|---|
| [6751] | 45 | |
|---|
| [11912] | 46 | #ifdef USE_FREETYPE |
|---|
| 47 | USE_OSGPLUGIN(freetype) |
|---|
| 48 | #endif |
|---|
| 49 | |
|---|
| 50 | USE_DOTOSGWRAPPER_LIBRARY(osg) |
|---|
| 51 | USE_DOTOSGWRAPPER_LIBRARY(osgFX) |
|---|
| 52 | USE_DOTOSGWRAPPER_LIBRARY(osgParticle) |
|---|
| 53 | USE_DOTOSGWRAPPER_LIBRARY(osgShadow) |
|---|
| 54 | USE_DOTOSGWRAPPER_LIBRARY(osgSim) |
|---|
| 55 | USE_DOTOSGWRAPPER_LIBRARY(osgTerrain) |
|---|
| 56 | USE_DOTOSGWRAPPER_LIBRARY(osgText) |
|---|
| 57 | USE_DOTOSGWRAPPER_LIBRARY(osgViewer) |
|---|
| 58 | USE_DOTOSGWRAPPER_LIBRARY(osgVolume) |
|---|
| 59 | USE_DOTOSGWRAPPER_LIBRARY(osgWidget) |
|---|
| 60 | |
|---|
| 61 | USE_SERIALIZER_WRAPPER_LIBRARY(osg) |
|---|
| 62 | USE_SERIALIZER_WRAPPER_LIBRARY(osgAnimation) |
|---|
| 63 | USE_SERIALIZER_WRAPPER_LIBRARY(osgFX) |
|---|
| 64 | USE_SERIALIZER_WRAPPER_LIBRARY(osgManipulator) |
|---|
| 65 | USE_SERIALIZER_WRAPPER_LIBRARY(osgParticle) |
|---|
| 66 | USE_SERIALIZER_WRAPPER_LIBRARY(osgShadow) |
|---|
| 67 | USE_SERIALIZER_WRAPPER_LIBRARY(osgSim) |
|---|
| 68 | USE_SERIALIZER_WRAPPER_LIBRARY(osgTerrain) |
|---|
| 69 | USE_SERIALIZER_WRAPPER_LIBRARY(osgText) |
|---|
| 70 | USE_SERIALIZER_WRAPPER_LIBRARY(osgVolume) |
|---|
| 71 | |
|---|
| [6927] | 72 | |
|---|
| [10282] | 73 | USE_GRAPHICSWINDOW() |
|---|
| [6751] | 74 | |
|---|
| 75 | int main(int argc, char** argv) |
|---|
| 76 | { |
|---|
| 77 | |
|---|
| 78 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 79 | |
|---|
| 80 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 81 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
|---|
| 82 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 83 | arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); |
|---|
| 84 | arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); |
|---|
| 85 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); |
|---|
| 86 | arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environmental variables available"); |
|---|
| 87 | arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); |
|---|
| 88 | arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings."); |
|---|
| 89 | arguments.getApplicationUsage()->addCommandLineOption("--SingleThreaded","Select SingleThreaded threading model for viewer."); |
|---|
| 90 | arguments.getApplicationUsage()->addCommandLineOption("--CullDrawThreadPerContext","Select CullDrawThreadPerContext threading model for viewer."); |
|---|
| 91 | arguments.getApplicationUsage()->addCommandLineOption("--DrawThreadPerContext","Select DrawThreadPerContext threading model for viewer."); |
|---|
| 92 | arguments.getApplicationUsage()->addCommandLineOption("--CullThreadPerCameraDrawThreadPerContext","Select CullThreadPerCameraDrawThreadPerContext threading model for viewer."); |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | bool helpAll = arguments.read("--help-all"); |
|---|
| 96 | unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | |
|---|
| 97 | ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | |
|---|
| 98 | ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); |
|---|
| 99 | if (helpType) |
|---|
| 100 | { |
|---|
| 101 | arguments.getApplicationUsage()->write(std::cout, helpType); |
|---|
| 102 | return 1; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | if (arguments.errors()) |
|---|
| 107 | { |
|---|
| 108 | arguments.writeErrorMessages(std::cout); |
|---|
| 109 | return 1; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | if (arguments.argc()<=1) |
|---|
| 113 | { |
|---|
| 114 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 115 | return 1; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | osgViewer::Viewer viewer; |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | { |
|---|
| 122 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
|---|
| 123 | |
|---|
| 124 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
|---|
| 125 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
|---|
| 126 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
|---|
| 127 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
|---|
| 128 | |
|---|
| 129 | std::string pathfile; |
|---|
| 130 | char keyForAnimationPath = '5'; |
|---|
| 131 | while (arguments.read("-p",pathfile)) |
|---|
| 132 | { |
|---|
| 133 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
|---|
| 134 | if (apm || !apm->valid()) |
|---|
| 135 | { |
|---|
| 136 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
|---|
| 137 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
|---|
| 138 | keyswitchManipulator->selectMatrixManipulator(num); |
|---|
| 139 | ++keyForAnimationPath; |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | viewer.addEventHandler(new osgViewer::StatsHandler); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | viewer.addEventHandler(new osgViewer::HelpHandler(arguments.getApplicationUsage())); |
|---|
| 160 | |
|---|
| 161 | while (arguments.read("--SingleThreaded")) viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); |
|---|
| 162 | while (arguments.read("--CullDrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); |
|---|
| 163 | while (arguments.read("--DrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); |
|---|
| 164 | while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) viewer.setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); |
|---|
| 165 | |
|---|
| 166 | unsigned int screenNum; |
|---|
| 167 | while (arguments.read("--screen",screenNum)) |
|---|
| 168 | { |
|---|
| 169 | viewer.setUpViewOnSingleScreen(screenNum); |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 174 | if (!loadedModel) |
|---|
| 175 | { |
|---|
| 176 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 177 | return 1; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | if (arguments.errors()) |
|---|
| 185 | { |
|---|
| 186 | arguments.writeErrorMessages(std::cout); |
|---|
| 187 | return 1; |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | osgUtil::Optimizer optimizer; |
|---|
| 193 | optimizer.optimize(loadedModel.get()); |
|---|
| 194 | |
|---|
| 195 | viewer.setSceneData( loadedModel.get() ); |
|---|
| 196 | |
|---|
| 197 | return viewer.run(); |
|---|
| 198 | } |
|---|