#include <simgear_config.h>
#endif
-#include <simgear/compiler.h>
-
#include <string.h> // for strcmp()
#include <vector>
#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"
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.
animation = new SGFlashAnimation(node);
} else if (!strcmp("dist-scale", type)) {
animation = new SGDistScaleAnimation(node);
+ } else if (!strcmp("noshadow", type)) {
+ animation = new SGShadowAnimation(prop_root, node);
+ } else if (!strcmp("shader", type)) {
+ animation = new SGShaderAnimation(prop_root, node);
} else {
animation = new SGNullAnimation(node);
SG_LOG(SG_INPUT, SG_WARN, "Unknown animation type " << type);
for (int i = 0; i<nb; i++) {
ssgEntity *e = b->getKid(i);
if (e->isAKindOf(ssgTypeLeaf())) {
+ if( ((ssgLeaf*)e)->getNumVertices() > 0)
((ssgLeaf*)e)->makeDList();
} else if (e->isAKindOf(ssgTypeBranch()) && ignore.find((ssgBranch *)e) == ignore.end()) {
makeDList( (ssgBranch*)e, ignore );
}
}
+class SGLoaderOptions : public ssgLoaderOptions {
+public:
+ SGLoaderOptions() { ssgSetCurrentOptions( this ); } // Install our own loader options at startup
+ void endLoad() {} // Avoid clearing the texture cache after every model load
+};
+
+static SGLoaderOptions loaderOptions;
\f
////////////////////////////////////////////////////////////////////////
ssgBranch *
sgLoad3DModel( const string &fg_root, const string &path,
SGPropertyNode *prop_root,
- double sim_time_sec, ssgEntity *(*load_panel)(SGPropertyNode *) )
+ double sim_time_sec, ssgEntity *(*load_panel)(SGPropertyNode *),
+ SGModelData *data )
{
ssgBranch * model = 0;
SGPropertyNode props;
ssgTexturePath((char *)texturepath.c_str());
model = (ssgBranch *)ssgLoad((char *)modelpath.c_str());
if (model == 0)
- throw sg_exception("Failed to load 3D model");
+ throw sg_io_exception("Failed to load 3D model",
+ sg_location(modelpath.str()));
}
// Set up the alignment node
ssgTransform * alignmainmodel = new ssgTransform;
node->getFloatValue("offsets/z-m", 0.0));
align->setTransform(res_matrix);
- ssgBranch * kid = sgLoad3DModel( fg_root, node->getStringValue("path"),
- prop_root, sim_time_sec, load_panel );
+ ssgBranch * kid;
+ const char * submodel = node->getStringValue("path");
+ try {
+ kid = sgLoad3DModel( fg_root, submodel, prop_root, sim_time_sec, load_panel );
+
+ } catch (const sg_throwable &t) {
+ SG_LOG(SG_INPUT, SG_ALERT, "Failed to load submodel: " << t.getFormattedMessage());
+ throw;
+ }
+
+ SGPropertyNode *cond = node->getNode("condition", false);
+ if (cond) {
+ align->setUserData(new SGConditionalRender(sgReadCondition(prop_root, cond)));
+ align->setTravCallback(SSG_CALLBACK_PRETRAV, model_condition_callback);
+ }
+
align->addKid(kid);
align->setName(node->getStringValue("name", ""));
model->addKid(align);
}
+ if ( load_panel ) {
+ // Load panels
+ vector<SGPropertyNode_ptr> 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);
+ }
+ }
+
+ if (data) {
+ alignmainmodel->setUserData(data);
+ data->modelLoaded(path, &props, alignmainmodel);
+ }
// Load animations
set<ssgBranch *> ignore_branches;
vector<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation");
}
#endif
- if ( load_panel ) {
- // Load panels
- vector<SGPropertyNode_ptr> 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);
- }
- }
+ int m = props.getIntValue("dump", 0);
+ if (m > 0)
+ model->print(stderr, "", m - 1);
return alignmainmodel;
}
return old;
}
+bool
+sgCheckAnimationBranch (ssgEntity * entity)
+{
+ return entity->getTravCallback(SSG_CALLBACK_PRETRAV) == animation_callback;
+}
// end of model.cxx