4 #include <osg/ArgumentParser>
5 #include <osgDB/ReadFile>
6 #include <osgViewer/Viewer>
8 #include <simgear/props/props.hxx>
9 #include <simgear/misc/sg_path.hxx>
10 #include <simgear/scene/material/matlib.hxx>
11 #include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
12 #include <simgear/scene/tgdb/userdata.hxx>
13 #include <simgear/scene/tgdb/TileEntry.hxx>
14 #include <simgear/scene/model/ModelRegistry.hxx>
15 #include <simgear/scene/model/modellib.hxx>
17 class DummyLoadHelper : public simgear::ModelLoadHelper {
19 virtual osg::Node *loadTileModel(const string& modelPath, bool)
22 SGSharedPtr<SGPropertyNode> prop = new SGPropertyNode;
23 return simgear::SGModelLib::loadModel(modelPath, prop);
25 std::cerr << "Error loading \"" << modelPath << "\"" << std::endl;
32 main(int argc, char** argv)
34 // Just reference simgears reader writer stuff so that the globals get
35 // pulled in by the linker ...
36 // FIXME: make that more explicit clear and call an initialization function
37 simgear::ModelRegistry::instance();
39 DummyLoadHelper dummyLoadHelper;
40 simgear::TileEntry::setModelLoadHelper(&dummyLoadHelper);
42 // use an ArgumentParser object to manage the program arguments.
43 osg::ArgumentParser arguments(&argc, argv);
45 // construct the viewer.
46 osgViewer::Viewer viewer(arguments);
47 // ... for some reason, get rid of that FIXME!
48 viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
50 const char *fg_root_env = std::getenv("FG_ROOT");
53 fg_root = fg_root_env;
57 const char *fg_scenery_env = std::getenv("FG_SCENERY");
58 string_list path_list;
60 path_list = sgPathSplit(fg_scenery_env);
63 path.append("Scenery");
64 path_list.push_back(path.str());
66 osgDB::FilePathList filePathList;
67 for (unsigned i = 0; i < path_list.size(); ++i) {
68 SGPath pt(path_list[i]), po(path_list[i]);
71 filePathList.push_back(path_list[i]);
72 filePathList.push_back(pt.str());
73 filePathList.push_back(po.str());
76 SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
77 props->getNode("sim/startup/season", true)->setStringValue("summer");
78 SGMaterialLib* ml = new SGMaterialLib;
79 SGPath mpath(fg_root);
80 mpath.append("materials.xml");
81 ml->load(fg_root, mpath.str(), props);
83 SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions;
84 btgOptions->getDatabasePathList() = filePathList;
85 btgOptions->setMatlib(ml);
87 // read the scene from the list of file specified command line args.
88 osg::ref_ptr<osg::Node> loadedModel;
89 loadedModel = osgDB::readNodeFiles(arguments, btgOptions);
91 // if no model has been successfully loaded report failure.
92 if (!loadedModel.valid()) {
93 std::cout << arguments.getApplicationName()
94 << ": No data loaded" << std::endl;
98 // pass the loaded scene graph to the viewer.
99 viewer.setSceneData(loadedModel.get());