]> git.mxchange.org Git - simgear.git/commitdiff
allow to switch on/off at runtime a whole imported <model> via <condition>:
authormfranz <mfranz>
Tue, 24 Oct 2006 19:44:38 +0000 (19:44 +0000)
committermfranz <mfranz>
Tue, 24 Oct 2006 19:44:38 +0000 (19:44 +0000)
  <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.

simgear/scene/model/model.cxx

index 7900114b37ff449319ee108ac77f00ae32289516..449ee51bbe3113cea2b1de2dea3a9fb22417e40f 100644 (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);