From 5e3ec6209cbde02627564204415fd5c84d6dd6db Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Thu, 19 Jul 2012 22:06:08 +0100 Subject: [PATCH] Add command to reload materials definitions. Note that this explicitly does not attempt to delete the old materials definitions, as they may be in use at the time. --- src/Main/fg_commands.cxx | 25 +++++++++++++++++++++++++ src/Scenery/tilemgr.cxx | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 9c11836ae..21711098b 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -531,6 +531,30 @@ do_tile_cache_reload (const SGPropertyNode * arg) return true; } +/** + * Reload the materials definition + */ + static bool + do_materials_reload (const SGPropertyNode * arg) + { + SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials"); + SGMaterialLib* new_matlib = new SGMaterialLib; + SGPath mpath( globals->get_fg_root() ); + mpath.append( fgGetString("/sim/rendering/materials-file") ); + bool loaded = new_matlib->load(globals->get_fg_root(), + mpath.str(), + globals->get_props()); + + if ( ! loaded ) { + SG_LOG( SG_GENERAL, SG_ALERT, + "Error loading materials file " << mpath.str() ); + return false; + } + + globals->set_matlib(new_matlib); + return true; + } + #if 0 These do_set_(some-environment-parameters) are deprecated and no longer @@ -1531,6 +1555,7 @@ static struct { { "dump-terrainbranch", do_dump_terrain_branch }, { "print-visible-scene", do_print_visible_scene_info }, { "reload-shaders", do_reload_shaders }, + { "reload-materials", do_materials_reload }, { 0, 0 } // zero-terminated }; diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 5a9679221..e05133a3e 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -108,6 +108,9 @@ void FGTileMgr::reinit() return; fgSetBool("/sim/sceneryloaded",false); fgSetDouble("/sim/startup/splash-alpha", 1.0); + + // Reload the materials definitions + _options->setMaterialLib(globals->get_matlib()); // remove all old scenery nodes from scenegraph and clear cache osg::Group* group = globals->get_scenery()->get_terrain_branch(); -- 2.39.5