From 8f64d4820cbe92d90eedcdb4714ffcfa95f96f24 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 21 Nov 2007 20:51:49 +0000 Subject: [PATCH] Add a command to dump just the terrain portion of the scene graph to a .osg file. Possible uses of this functionality could include converting the model to some other format or coordinate system for use in some other visualization or simulation. --- src/GUI/gui.h | 1 + src/GUI/gui_funcs.cxx | 49 ++++++++++++++++++++++++++++++++++++++-- src/Main/fg_commands.cxx | 18 +++++++++++++++ src/Main/renderer.cxx | 7 ++++++ src/Main/renderer.hxx | 1 + 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/GUI/gui.h b/src/GUI/gui.h index 31e65bb10..bc27d9a30 100644 --- a/src/GUI/gui.h +++ b/src/GUI/gui.h @@ -48,6 +48,7 @@ extern void guiErrorMessage(const char *txt, const sg_throwable &throwable); extern void fgDumpSnapShot(); extern void fgDumpSceneGraph(); +extern void fgDumpTerrainBranch(); extern puFont guiFnt; extern fntTexFont *guiFntHandle; diff --git a/src/GUI/gui_funcs.cxx b/src/GUI/gui_funcs.cxx index 413c65bd5..6a57dc1d6 100644 --- a/src/GUI/gui_funcs.cxx +++ b/src/GUI/gui_funcs.cxx @@ -591,7 +591,7 @@ void fgDumpSnapShot () { } } -// do a screen snap shot +// do an entire scenegraph dump void fgDumpSceneGraph() { char *filename = new char [24]; @@ -617,7 +617,52 @@ void fgDumpSceneGraph() } if ( fgDumpSceneGraphToFile(filename)) { - message = "Scene graphe saved to \""; + message = "Entire scene graph saved to \""; + message += filename; + message += "\"."; + } else { + message = "Failed to save to \""; + message += filename; + message += "\"."; + } + + mkDialog (message.c_str()); + + delete [] filename; + + if ( !freeze ) { + fgSetBool("/sim/freeze/master", false); + } +} + + +// do an terrain branch dump +void fgDumpTerrainBranch() +{ + char *filename = new char [24]; + string message; + static int count = 1; + + FGRenderer *renderer = globals->get_renderer(); + + static const SGPropertyNode *master_freeze + = fgGetNode("/sim/freeze/master"); + + bool freeze = master_freeze->getBoolValue(); + if ( !freeze ) { + fgSetBool("/sim/freeze/master", true); + } + + while (count < 1000) { + FILE *fp; + snprintf(filename, 24, "fgfs-graph-%03d.osg", count++); + if ( (fp = fopen(filename, "r")) == NULL ) + break; + fclose(fp); + } + + if ( fgDumpTerrainBranchToFile(filename)) { + message = "Terrain graph saved to \""; message += filename; message += "\"."; } else { diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index cd637d77b..455baea8b 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -494,6 +494,23 @@ do_dump_scene_graph (const SGPropertyNode*) return true; } +static bool +do_dump_terrain_branch (const SGPropertyNode*) +{ + fgDumpTerrainBranch(); + + double lon_deg = fgGetDouble("/position/longitude-deg"); + double lat_deg = fgGetDouble("/position/latitude-deg"); + SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0); + SGVec3d zero = SGVec3d::fromGeod(geodPos); + + SG_LOG(SG_INPUT, SG_INFO, "Model parameters:"); + SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() ); + SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg ); + + return true; +} + /** * Built-in command: hires capture screen. */ @@ -1471,6 +1488,7 @@ static struct { { "press-cockpit-button", do_press_cockpit_button }, { "release-cockpit-button", do_release_cockpit_button }, { "dump-scenegraph", do_dump_scene_graph }, + { "dump-terrainbranch", do_dump_terrain_branch }, { 0, 0 } // zero-terminated }; diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index 59b879743..7b26b30b8 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -1071,5 +1071,12 @@ fgDumpSceneGraphToFile(const char* filename) return osgDB::writeNodeFile(*mRealRoot.get(), filename); } +bool +fgDumpTerrainBranchToFile(const char* filename) +{ + return osgDB::writeNodeFile( *globals->get_scenery()->get_terrain_branch(), + filename ); +} + // end of renderer.cxx diff --git a/src/Main/renderer.hxx b/src/Main/renderer.hxx index 3fb7e0f83..de21b932e 100644 --- a/src/Main/renderer.hxx +++ b/src/Main/renderer.hxx @@ -81,5 +81,6 @@ protected: }; bool fgDumpSceneGraphToFile(const char* filename); +bool fgDumpTerrainBranchToFile(const char* filename); #endif