if (!_models_loaded) {
for (unsigned int i = 0; i < _paths.size(); i++) {
ssgEntity *entity = modellib->load_model( fg_root, _paths[i],
- prop_root, sim_time_sec );
+ prop_root, sim_time_sec,
+ /*cache_object*/ true );
if (entity != 0) {
// FIXME: this stuff can be handled
// in the XML wrapper as well (at least,
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;
model->addKid(panel);
}
}
+
+ if (data) {
+ data->modelLoaded(path, &props, model);
+ model->setUserData(data);
+ }
// Load animations
set<ssgBranch *> ignore_branches;
vector<SGPropertyNode_ptr> animation_nodes = props.getChildren("animation");
}
#endif
+ int m = props.getIntValue("dump", 0);
+ if (m > 0)
+ model->print(stderr, "", m - 1);
return alignmainmodel;
}
#endif
+/**
+ * Abstract class for adding data to the scene graph. modelLoaded() is
+ * called by sgLoad3DModel() after the model was loaded, and the destructor
+ * when the branch is removed from the graph.
+ */
+class SGModelData : public ssgBase {
+public:
+ virtual ~SGModelData() {}
+ virtual void modelLoaded( const string& path, SGPropertyNode *prop,
+ ssgBranch *branch) {}
+};
+
+
/**
* Load a 3D model with or without XML wrapper. Note, this version
* Does not know about or load the panel/cockpit information. Use the
ssgBranch *
sgLoad3DModel( const string& fg_root, const string &path,
SGPropertyNode *prop_root, double sim_time_sec,
- ssgEntity *(*load_panel)(SGPropertyNode *) = 0 );
+ ssgEntity *(*load_panel)(SGPropertyNode *) = 0,
+ SGModelData *data = 0 );
/**
SGModelLib::load_model( const string &fg_root,
const string &path,
SGPropertyNode *prop_root,
- double sim_time_sec )
+ double sim_time_sec,
+ bool cache_object,
+ SGModelData *data )
{
ssgBranch *personality_branch = new SGPersonalityBranch;
personality_branch->setTravCallback(SSG_CALLBACK_PRETRAV, personality_pretrav_callback);
// FIXME: normalize path to
// avoid duplicates.
map<string, ssgSharedPtr<ssgEntity> >::iterator it = _table.find(path);
- if (it == _table.end()) {
+ if (!cache_object || it == _table.end()) {
ssgSharedPtr<ssgEntity> model = sgLoad3DModel(fg_root, path, prop_root,
- sim_time_sec );
- _table[path] = model; // add one reference to keep it around
+ sim_time_sec, 0, data );
+ if (cache_object)
+ _table[path] = model; // add one reference to keep it around
+
personality_branch->addKid( model );
} else {
personality_branch->addKid( it->second );
#include <simgear/structure/ssgSharedPtr.hxx>
#include <simgear/props/props.hxx>
+#include "model.hxx"
SG_USING_STD(map);
SG_USING_STD(string);
virtual ssgEntity *load_model( const string &fg_root,
const string &path,
SGPropertyNode *prop_root,
- double sim_time_sec );
+ double sim_time_sec,
+ bool cache_object,
+ SGModelData *data = 0 );
protected:
map<string,ssgSharedPtr<ssgEntity> > _table;