allow to switch on/off at runtime a whole imported <model> via <condition>:

<model>
      <path>some/model.xml</path>
      <condition>
          <property>model/switch</property>
      </condition>
  </model>

Of course, one could add "select" animations for all <object-name> in the
<model>, 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.
This commit is contained in:
mfranz
2006-10-24 19:44:38 +00:00
parent f8303b4623
commit 5876052170
+25
View File
@@ -19,6 +19,7 @@
#include <simgear/structure/exception.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/props/condition.hxx>
#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);