From 0c0b38733e8c3b6891a2381a7ad7b39ab54746dd Mon Sep 17 00:00:00 2001 From: frohlich Date: Fri, 22 May 2009 18:23:01 +0000 Subject: [PATCH] Add a new tool called fgviewer. Modified Files: configure.ac utils/Makefile.am Added Files: utils/fgviewer/.cvsignore utils/fgviewer/Makefile.am utils/fgviewer/fgviewer.cxx --- configure.ac | 1 + utils/Makefile.am | 2 +- utils/fgviewer/.cvsignore | 4 ++ utils/fgviewer/Makefile.am | 15 ++++++ utils/fgviewer/fgviewer.cxx | 102 ++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 utils/fgviewer/.cvsignore create mode 100644 utils/fgviewer/Makefile.am create mode 100644 utils/fgviewer/fgviewer.cxx diff --git a/configure.ac b/configure.ac index 3ea1d4f50..1af45ab9d 100644 --- a/configure.ac +++ b/configure.ac @@ -729,6 +729,7 @@ AC_CONFIG_FILES([ \ utils/propmerge/Makefile \ utils/TerraSync/Makefile \ utils/xmlgrep/Makefile \ + utils/fgviewer/Makefile \ ]) AC_OUTPUT diff --git a/utils/Makefile.am b/utils/Makefile.am index 5989c57f1..1f183fec5 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -1,4 +1,4 @@ DIST_SUBDIRS = GPSsmooth TerraSync Modeller js_server fgadmin xmlgrep propmerge -SUBDIRS = GPSsmooth TerraSync Modeller js_server propmerge +SUBDIRS = GPSsmooth TerraSync Modeller js_server propmerge fgviewer diff --git a/utils/fgviewer/.cvsignore b/utils/fgviewer/.cvsignore new file mode 100644 index 000000000..d14287d53 --- /dev/null +++ b/utils/fgviewer/.cvsignore @@ -0,0 +1,4 @@ +.deps +Makefile +Makefile.in +fgviewer diff --git a/utils/fgviewer/Makefile.am b/utils/fgviewer/Makefile.am new file mode 100644 index 000000000..c0384d803 --- /dev/null +++ b/utils/fgviewer/Makefile.am @@ -0,0 +1,15 @@ +bin_PROGRAMS = fgviewer + +fgviewer_SOURCES = fgviewer.cxx +fgviewer_LDADD = \ + -lsgroute -lsgsky -lsgsound -lsgephem -lsgtgdb -lsgmaterial -lsgmodel \ + -lsgbvh -lsgutil -lsgtiming -lsgio -lsgscreen -lsgmath -lsgbucket \ + -lsgprops -lsgdebug -lsgmagvar -lsgmisc -lsgnasal -lsgxml -lsgsound \ + -lsgserial -lsgstructure -lsgenvironment \ + -lplibul \ + $(OSG_LIBS) \ + $(THREAD_LIBS) \ + $(network_LIBS) \ + -lz \ + $(opengl_LIBS) \ + $(openal_LIBS) diff --git a/utils/fgviewer/fgviewer.cxx b/utils/fgviewer/fgviewer.cxx new file mode 100644 index 000000000..83ab2c48f --- /dev/null +++ b/utils/fgviewer/fgviewer.cxx @@ -0,0 +1,102 @@ +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class DummyLoadHelper : public simgear::ModelLoadHelper { +public: + virtual osg::Node *loadTileModel(const string& modelPath, bool) + { + try { + SGSharedPtr prop = new SGPropertyNode; + return simgear::SGModelLib::loadModel(modelPath, prop); + } catch (...) { + std::cerr << "Error loading \"" << modelPath << "\"" << std::endl; + return 0; + } + } +}; + +int +main(int argc, char** argv) +{ + // Just reference simgears reader writer stuff so that the globals get + // pulled in by the linker ... + // FIXME: make that more explicit clear and call an initialization function + simgear::ModelRegistry::instance(); + sgUserDataInit(0); + DummyLoadHelper dummyLoadHelper; + simgear::TileEntry::setModelLoadHelper(&dummyLoadHelper); + + // use an ArgumentParser object to manage the program arguments. + osg::ArgumentParser arguments(&argc, argv); + + // construct the viewer. + osgViewer::Viewer viewer(arguments); + // ... for some reason, get rid of that FIXME! + viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); + + const char *fg_root_env = std::getenv("FG_ROOT"); + std::string fg_root; + if (fg_root_env) + fg_root = fg_root_env; + else + fg_root = "."; + + const char *fg_scenery_env = std::getenv("FG_SCENERY"); + string_list path_list; + if (fg_scenery_env) { + path_list = sgPathSplit(fg_scenery_env); + } else { + SGPath path(fg_root); + path.append("Scenery"); + path_list.push_back(path.str()); + } + osgDB::FilePathList filePathList; + for (unsigned i = 0; i < path_list.size(); ++i) { + SGPath pt(path_list[i]), po(path_list[i]); + pt.append("Terrain"); + po.append("Objects"); + filePathList.push_back(path_list[i]); + filePathList.push_back(pt.str()); + filePathList.push_back(po.str()); + } + + SGSharedPtr props = new SGPropertyNode; + props->getNode("sim/startup/season", true)->setStringValue("summer"); + SGMaterialLib* ml = new SGMaterialLib; + SGPath mpath(fg_root); + mpath.append("materials.xml"); + ml->load(fg_root, mpath.str(), props); + + SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions; + btgOptions->getDatabasePathList() = filePathList; + btgOptions->setMatlib(ml); + + // read the scene from the list of file specified command line args. + osg::ref_ptr loadedModel; + loadedModel = osgDB::readNodeFiles(arguments, btgOptions); + + // if no model has been successfully loaded report failure. + if (!loadedModel.valid()) { + std::cout << arguments.getApplicationName() + << ": No data loaded" << std::endl; + return EXIT_FAILURE; + } + + // pass the loaded scene graph to the viewer. + viewer.setSceneData(loadedModel.get()); + + return viewer.run(); +}