4 #include <osg/ArgumentParser>
5 #include <osgDB/ReadFile>
6 #include <osgViewer/Viewer>
7 #include <osgViewer/ViewerEventHandlers>
9 #include <simgear/props/props.hxx>
10 #include <simgear/misc/sg_path.hxx>
11 #include <simgear/scene/material/matlib.hxx>
12 #include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
13 #include <simgear/scene/tgdb/userdata.hxx>
14 #include <simgear/scene/tgdb/TileEntry.hxx>
15 #include <simgear/scene/model/ModelRegistry.hxx>
16 #include <simgear/scene/model/modellib.hxx>
18 class DummyLoadHelper : public simgear::ModelLoadHelper {
20 virtual osg::Node *loadTileModel(const string& modelPath, bool)
23 SGSharedPtr<SGPropertyNode> prop = new SGPropertyNode;
24 return simgear::SGModelLib::loadModel(modelPath, prop);
26 std::cerr << "Error loading \"" << modelPath << "\"" << std::endl;
33 main(int argc, char** argv)
35 // Just reference simgears reader writer stuff so that the globals get
36 // pulled in by the linker ...
37 // FIXME: make that more explicit clear and call an initialization function
38 simgear::ModelRegistry::instance();
40 DummyLoadHelper dummyLoadHelper;
41 simgear::TileEntry::setModelLoadHelper(&dummyLoadHelper);
43 // use an ArgumentParser object to manage the program arguments.
44 osg::ArgumentParser arguments(&argc, argv);
46 // construct the viewer.
47 osgViewer::Viewer viewer(arguments);
48 // ... for some reason, get rid of that FIXME!
49 viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
52 viewer.addEventHandler(new osgViewer::HelpHandler);
53 viewer.addEventHandler(new osgViewer::StatsHandler);
55 // viewer.addEventHandler(new osgViewer::ThreadingHandler);
56 viewer.addEventHandler(new osgViewer::LODScaleHandler);
57 viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);
59 const char *fg_root_env = std::getenv("FG_ROOT");
62 fg_root = fg_root_env;
66 const char *fg_scenery_env = std::getenv("FG_SCENERY");
67 string_list path_list;
69 path_list = sgPathSplit(fg_scenery_env);
72 path.append("Scenery");
73 path_list.push_back(path.str());
75 osgDB::FilePathList filePathList;
76 for (unsigned i = 0; i < path_list.size(); ++i) {
77 SGPath pt(path_list[i]), po(path_list[i]);
80 filePathList.push_back(path_list[i]);
81 filePathList.push_back(pt.str());
82 filePathList.push_back(po.str());
85 SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
86 props->getNode("sim/startup/season", true)->setStringValue("summer");
87 SGMaterialLib* ml = new SGMaterialLib;
88 SGPath mpath(fg_root);
89 mpath.append("materials.xml");
90 ml->load(fg_root, mpath.str(), props);
92 SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions;
93 btgOptions->getDatabasePathList() = filePathList;
94 btgOptions->setMatlib(ml);
96 // read the scene from the list of file specified command line args.
97 osg::ref_ptr<osg::Node> loadedModel;
98 loadedModel = osgDB::readNodeFiles(arguments, btgOptions);
100 // if no model has been successfully loaded report failure.
101 if (!loadedModel.valid()) {
102 std::cout << arguments.getApplicationName()
103 << ": No data loaded" << std::endl;
107 // pass the loaded scene graph to the viewer.
108 viewer.setSceneData(loadedModel.get());