From ad81560be5e40572bff8c6db451fe299c40bf7da Mon Sep 17 00:00:00 2001 From: ehofman Date: Fri, 2 Apr 2004 14:38:57 +0000 Subject: [PATCH] Frederic Bouvier: add an optional parameter that would be called to build the aircraft panel, so that flightgear's model_panel no longer duplicate code. add a pretrav callback to models so that we can filter out models when calling ssgCullAndDraw on the global scene. sgSetModelFilter( true ) means that we want to draw the models. Use false to cull them out. --- simgear/scene/model/model.cxx | 39 +++++++++++++++++++++++++++++++++-- simgear/scene/model/model.hxx | 8 ++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index 39eb41c5..66de79b5 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -28,11 +28,24 @@ SG_USING_STD(vector); + +//////////////////////////////////////////////////////////////////////// +// Global state +//////////////////////////////////////////////////////////////////////// +static bool +model_filter = true; + //////////////////////////////////////////////////////////////////////// // Static utility functions. //////////////////////////////////////////////////////////////////////// +static int +model_filter_callback (ssgEntity * entity, int mask) +{ + return model_filter; +} + /** * Callback to update an animation. */ @@ -187,7 +200,7 @@ sgMakeAnimation( ssgBranch * model, ssgBranch * sgLoad3DModel( const string &fg_root, const string &path, SGPropertyNode *prop_root, - double sim_time_sec ) + double sim_time_sec, ssgEntity *(*load_panel)(SGPropertyNode *) ) { ssgBranch * model = 0; SGPropertyNode props; @@ -223,6 +236,8 @@ sgLoad3DModel( const string &fg_root, const string &path, // Set up the alignment node ssgTransform * alignmainmodel = new ssgTransform; + if ( load_panel == 0 ) + alignmainmodel->setTravCallback( SSG_CALLBACK_PRETRAV, model_filter_callback ); alignmainmodel->addKid(model); sgMat4 res_matrix; sgMakeOffsetsMatrix(&res_matrix, @@ -236,6 +251,18 @@ sgLoad3DModel( const string &fg_root, const string &path, unsigned int i; + if ( load_panel ) { + // Load panels + vector panel_nodes = props.getChildren("panel"); + for (i = 0; i < panel_nodes.size(); i++) { + SG_LOG(SG_INPUT, SG_DEBUG, "Loading a panel"); + ssgEntity * panel = load_panel(panel_nodes[i]); + if (panel_nodes[i]->hasValue("name")) + panel->setName((char *)panel_nodes[i]->getStringValue("name")); + model->addKid(panel); + } + } + // Load sub-models vector model_nodes = props.getChildren("model"); for (i = 0; i < model_nodes.size(); i++) { @@ -252,7 +279,7 @@ sgLoad3DModel( const string &fg_root, const string &path, align->setTransform(res_matrix); ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"), - prop_root, sim_time_sec ); + prop_root, sim_time_sec, load_panel ); align->addKid(kid); align->setName(node->getStringValue("name", "")); model->addKid(align); @@ -271,5 +298,13 @@ sgLoad3DModel( const string &fg_root, const string &path, return alignmainmodel; } +bool +sgSetModelFilter( bool filter ) +{ + bool old = model_filter; + model_filter = filter; + return old; +} + // end of model.cxx diff --git a/simgear/scene/model/model.hxx b/simgear/scene/model/model.hxx index 8cf417b5..564c4d41 100644 --- a/simgear/scene/model/model.hxx +++ b/simgear/scene/model/model.hxx @@ -43,7 +43,8 @@ SG_USING_STD(vector); */ ssgBranch * sgLoad3DModel( const string& fg_root, const string &path, - SGPropertyNode *prop_root, double sim_time_sec ); + SGPropertyNode *prop_root, double sim_time_sec, + ssgEntity *(*load_panel)(SGPropertyNode *) = 0 ); /** @@ -64,5 +65,10 @@ sgMakeAnimation( ssgBranch * model, SGPropertyNode_ptr node, double sim_time_sec ); +/** + * Set the filter state on models + */ +bool +sgSetModelFilter( bool filter ); #endif // __MODEL_HXX -- 2.39.5