# include <config.h>
#endif
-
#include <simgear/compiler.h>
-#include STL_STRING
+#include <string>
#include <osg/ref_ptr>
#include <osg/Node>
+#include <osgDB/FileUtils>
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/location.hxx>
-#include <simgear/scene/model/model.hxx>
+#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/props/props.hxx>
#include <Scripting/NasalSys.hxx>
#include "AIBase.hxx"
+#include "AIModelData.hxx"
#include "AIManager.hxx"
+const char *default_model = "Models/Geometry/glider.ac";
const double FGAIBase::e = 2.71828183;
const double FGAIBase::lbs_to_slugs = 0.031080950172; //conversion factor
+using namespace simgear;
FGAIBase::FGAIBase(object_type ot) :
props( NULL ),
_impact_speed(0),
_refID( _newAIModelID() ),
- _otype(ot)
+ _otype(ot),
+ _initialized(false)
{
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
if (!scFileNode)
return;
- setPath(scFileNode->getStringValue("model", "Models/Geometry/glider.ac"));
+ setPath(scFileNode->getStringValue("model",
+ fgGetString("/sim/multiplay/default-model", default_model)));
setHeading(scFileNode->getDoubleValue("heading", 0.0));
setSpeed(scFileNode->getDoubleValue("speed", 0.0));
}
bool FGAIBase::init(bool search_in_AI_path) {
+ osg::ref_ptr<osgDB::ReaderWriter::Options> opt=
+ new osgDB::ReaderWriter::Options(*osgDB::Registry::instance()->getOptions());
+
+ if(search_in_AI_path)
+ {
+ SGPath ai_path(globals->get_fg_root());
+ ai_path.append("AI");
+ opt->getDatabasePathList().push_front(ai_path.str());
+ }
- if (!model_path.empty()) {
-
- if ( search_in_AI_path
- && (model_path.substr(model_path.size() - 4, 4) == ".xml")) {
- SGPath ai_path("AI");
- ai_path.append(model_path);
- try {
- model = load3DModel( globals->get_fg_root(), ai_path.str(), props,
- globals->get_sim_time_sec() );
- } catch (const sg_exception &e) {
- model = NULL;
- }
- } else
- model = NULL;
-
- if (!model.get()) {
- try {
- model = load3DModel( globals->get_fg_root(), model_path, props,
- globals->get_sim_time_sec() );
- } catch (const sg_exception &e) {
- model = NULL;
- }
- }
+ string f = osgDB::findDataFile(model_path, opt.get());
- }
+ if(f.empty())
+ f = fgGetString("/sim/multiplay/default-model", default_model);
+
+ model = load3DModel(f, props);
- if (model.get()) {
+ if (model.valid() && _initialized == false) {
+ model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
aip.init( model.get() );
aip.setVisible(true);
invisible = false;
globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
+ _initialized = true;
+
+ } else if (!model_path.empty()) {
+ SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);
+ }
+
+ setDie(false);
+ return true;
+}
+
+void FGAIBase::initModel(osg::Node *node)
+{
+ if (model.valid()) {
fgSetString("/ai/models/model-added", props->getPath());
} else if (!model_path.empty()) {
props->setStringValue("submodels/path", _path.c_str());
setDie(false);
- return true;
}
-osg::Node* FGAIBase::load3DModel(const string& fg_root,
- const string &path,
- SGPropertyNode *prop_root,
- double sim_time_sec)
+osg::Node* FGAIBase::load3DModel(const string &path, SGPropertyNode *prop_root)
{
- model = sgLoad3DModel(fg_root, path, prop_root, sim_time_sec, 0,
- new FGNasalModelData(prop_root));
- model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
+ model = SGModelLib::loadPagedModel(path, prop_root, new FGAIModelData(this, prop_root));
return model.get();
}