From 876e81edbdf78acd9d0a1ccf53059cfe6682feb5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 23 Feb 2014 11:51:21 -0800 Subject: [PATCH] AIModels use PagedLOD - allows AIModels to be unloaded by the Pager - move AI models into the 'models' sub-branch of FGScenery --- src/AIModel/AIBase.cxx | 19 +++++++++---------- src/AIModel/AIBase.hxx | 9 +++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index a648a35c9..3e00f5542 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -207,7 +207,7 @@ FGAIBase::removeModel() if (pSceneryManager) { osg::ref_ptr temp = _model.get(); - pSceneryManager->get_scene_graph()->removeChild(aip.getSceneGraph()); + pSceneryManager->get_models_branch()->removeChild(aip.getSceneGraph()); // withdraw from SGModelPlacement and drop own reference (unref) aip.clear(); _modeldata = 0; @@ -365,26 +365,25 @@ bool FGAIBase::init(bool search_in_AI_path) _installed = true; _modeldata = new FGAIModelData(props); - osg::Node * mdl = SGModelLib::loadDeferredModel(f, props, _modeldata); + _model= SGModelLib::loadPagedModel(f, props, _modeldata); - _model = new osg::LOD; _model->setName("AI-model range animation node"); - _model->addChild( mdl, 0, FLT_MAX ); - _model->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER); - _model->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT); + // _model->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER); + // _model->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT); + // We really need low-resolution versions of AI/MP aircraft. // Or at least dummy "stubs" with some default silhouette. // _model->addChild( SGModelLib::loadPagedModel(fgGetString("/sim/multiplay/default-model", default_model), // props, new FGNasalModelData(props)), FLT_MAX, FLT_MAX); updateLOD(); - - initModel(mdl); + initModel(); + if (_model.valid() && _initialized == false) { aip.init( _model.get() ); aip.setVisible(true); invisible = false; - globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph()); + globals->get_scenery()->get_models_branch()->addChild(aip.getSceneGraph()); _initialized = true; SG_LOG(SG_AI, SG_DEBUG, "AIBase: Loaded model " << model_path); @@ -399,7 +398,7 @@ bool FGAIBase::init(bool search_in_AI_path) return true; } -void FGAIBase::initModel(osg::Node *node) +void FGAIBase::initModel() { if (_model.valid()) { diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 52be8e5a3..dd88987cd 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -21,8 +21,7 @@ #define _FG_AIBASE_HXX #include - -#include +#include #include #include @@ -36,6 +35,8 @@ #include
+namespace osg { class PagedLOD; } + namespace simgear { class BVHMaterial; } @@ -59,7 +60,7 @@ public: virtual void readFromScenario(SGPropertyNode* scFileNode); virtual bool init(bool search_in_AI_path=false); - virtual void initModel(osg::Node *node); + virtual void initModel(); virtual void update(double dt); virtual void bind(); virtual void unbind(); @@ -233,7 +234,7 @@ private: int _refID; object_type _otype; bool _initialized; - osg::ref_ptr _model; //The 3D model LOD object + osg::ref_ptr _model; osg::ref_ptr _modeldata; -- 2.39.5