From: mfranz Date: Tue, 24 Oct 2006 19:44:38 +0000 (+0000) Subject: allow to switch on/off at runtime a whole imported via : X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=58760521704391bc7f0da7124930322111718f88;p=simgear.git allow to switch on/off at runtime a whole imported via : some/model.xml model/switch Of course, one could add "select" animations for all in the , but this is tedious and can hardly be done e.g. for all objects in all instruments in $FG_ROOT/Aircraft/Instruments-3d/ etc. The feature will be used in the bo105, so that civilian variants can have a HSI instrument, where military variants have a TACAN etc. --- diff --git a/simgear/scene/model/model.cxx b/simgear/scene/model/model.cxx index 7900114b..449ee51b 100644 --- a/simgear/scene/model/model.cxx +++ b/simgear/scene/model/model.cxx @@ -19,6 +19,7 @@ #include #include #include +#include #include "animation.hxx" #include "model.hxx" @@ -64,6 +65,23 @@ restore_callback (ssgEntity * entity, int mask) return 1; } +/** + * Callback and userData class for conditional rendering. + */ +class SGConditionalRender : public ssgBase { +public: + SGConditionalRender(SGCondition *c) : _condition(c) {} + bool test() { return _condition->test(); } +private: + SGCondition *_condition; +}; + +static int +model_condition_callback (ssgEntity * entity, int mask) +{ + return ((SGConditionalRender *)entity->getUserData())->test(); +} + /** * Locate a named SSG node in a branch. @@ -333,6 +351,13 @@ sgLoad3DModel( const string &fg_root, const string &path, SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage()); throw; } + + SGPropertyNode_ptr cond_node = node->getNode("condition", false); + if (cond_node) { + align->setUserData(new SGConditionalRender(sgReadCondition(prop_root, cond_node))); + align->setTravCallback(SSG_CALLBACK_PRETRAV, model_condition_callback); + } + align->addKid(kid); align->setName(node->getStringValue("name", "")); model->addKid(align);