| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | #include <osgDB/ReadFile> |
|---|
| 13 | #include <osgUtil/Optimizer> |
|---|
| 14 | #include <osgUtil/Simplifier> |
|---|
| 15 | #include <osgProducer/Viewer> |
|---|
| 16 | |
|---|
| 17 | int main( int argc, char **argv ) |
|---|
| 18 | { |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 25 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
|---|
| 26 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 27 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | float sampleRatio = 0.5f; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | osgProducer::Viewer viewer(arguments); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | viewer.getUsage(*arguments.getApplicationUsage()); |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | while (arguments.read("-s",sampleRatio)) {} |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 46 | { |
|---|
| 47 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 48 | return 1; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | if (arguments.errors()) |
|---|
| 53 | { |
|---|
| 54 | arguments.writeErrorMessages(std::cout); |
|---|
| 55 | return 1; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (arguments.argc()<=1) |
|---|
| 59 | { |
|---|
| 60 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 61 | return 1; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | osg::Timer_t start_tick = osg::Timer::instance()->tick(); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | if (!loadedModel) |
|---|
| 71 | { |
|---|
| 72 | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
|---|
| 73 | return 1; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | arguments.reportRemainingOptionsAsUnrecognized(); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | if (arguments.errors()) |
|---|
| 81 | { |
|---|
| 82 | arguments.writeErrorMessages(std::cout); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | osg::Timer_t end_tick = osg::Timer::instance()->tick(); |
|---|
| 86 | |
|---|
| 87 | std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl; |
|---|
| 88 | |
|---|
| 89 | osgUtil::Simplifier simplifier(sampleRatio); |
|---|
| 90 | |
|---|
| 91 | loadedModel->accept(simplifier); |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | viewer.setSceneData(loadedModel.get()); |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | viewer.realize(); |
|---|
| 98 | |
|---|
| 99 | while( !viewer.done() ) |
|---|
| 100 | { |
|---|
| 101 | |
|---|
| 102 | viewer.sync(); |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | viewer.update(); |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | viewer.frame(); |
|---|
| 110 | |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | viewer.sync(); |
|---|
| 115 | |
|---|
| 116 | return 0; |
|---|
| 117 | } |
|---|