From 3451012bca81614748508cdb2041c25b5ceb1a02 Mon Sep 17 00:00:00 2001 From: ThorstenB Date: Mon, 3 Oct 2011 12:01:58 +0200 Subject: [PATCH] Make LOD properties of AI/MP aircraft run-time configurable. --- src/AIModel/AIBase.cxx | 50 +++++++++++++++++++++++++++------------ src/AIModel/AIBase.hxx | 3 ++- src/AIModel/AIManager.cxx | 19 ++++++++++++++- src/AIModel/AIManager.hxx | 4 ++++ 4 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 8a8e1c8f3..f967995f6 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -179,6 +179,27 @@ void FGAIBase::update(double dt) { ft_per_deg_lon = 365228.16 * cos(pos.getLatitudeRad()); } +/** update LOD properties of the model */ +void FGAIBase::updateLOD() +{ + double maxRangeDetail = fgGetDouble("/sim/rendering/static-lod/ai-detailed", 10000.0); + double maxRangeBare = fgGetDouble("/sim/rendering/static-lod/ai-bare", 20000.0); + if (_model.valid()) + { + if( maxRangeDetail == 0.0 ) + { + // disable LOD + _model->setRange(0, 0.0, FLT_MAX); + _model->setRange(1, FLT_MAX, FLT_MAX); + } + else + { + _model->setRange(0, 0.0, maxRangeDetail); + _model->setRange(1, maxRangeDetail,maxRangeBare); + } + } +} + void FGAIBase::Transform() { if (!invisible) { @@ -226,23 +247,22 @@ bool FGAIBase::init(bool search_in_AI_path) { _installed = true; osg::Node * mdl = SGModelLib::loadPagedModel(f, props, new FGNasalModelData(props)); - model = mdl; - double aiModelMaxRange = fgGetDouble("/sim/rendering/static-lod/ai", 0.0); - if( aiModelMaxRange > 0.0 ) { - osg::LOD * lod = new osg::LOD; - lod->setName("AI-model range animation node"); + _model = new osg::LOD; + _model->setName("AI-model range animation node"); - lod->addChild( mdl, 0, aiModelMaxRange ); - lod->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER); - lod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT); - - model = lod; - } + _model->addChild( mdl, 0, FLT_MAX ); + _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); - if (model.valid() && _initialized == false) { - aip.init( model.get() ); + if (_model.valid() && _initialized == false) { + aip.init( _model.get() ); aip.setVisible(true); invisible = false; globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph()); @@ -260,7 +280,7 @@ bool FGAIBase::init(bool search_in_AI_path) { void FGAIBase::initModel(osg::Node *node) { - if (model.valid()) { + if (_model.valid()) { if( _path != ""){ props->setStringValue("submodels/path", _path.c_str()); @@ -523,7 +543,7 @@ SGVec3d FGAIBase::getCartPos() const { bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev, const SGMaterial** material) const { return globals->get_scenery()->get_elevation_m(pos, elev, material, - model.get()); + _model.get()); } double FGAIBase::_getCartPosX() const { diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index fa85d5d2b..298d67cf0 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -64,6 +64,7 @@ public: virtual void unbind(); virtual void reinit() {} + void updateLOD(); void setManager(FGAIManager* mgr, SGPropertyNode* p); void setPath( const char* model ); void setSMPath( const string& p ); @@ -186,7 +187,6 @@ protected: double ht_diff; // value used by radar display instrument string model_path; //Path to the 3D model - osg::ref_ptr model; //The 3D model object SGModelPlacement aip; bool delete_me; @@ -222,6 +222,7 @@ private: int _refID; object_type _otype; bool _initialized; + osg::ref_ptr _model; //The 3D model LOD object public: object_type getType(); diff --git a/src/AIModel/AIManager.cxx b/src/AIModel/AIManager.cxx index 91ef65271..2ad548371 100644 --- a/src/AIModel/AIManager.cxx +++ b/src/AIModel/AIManager.cxx @@ -43,7 +43,12 @@ #include "AIGroundVehicle.hxx" #include "AIEscort.hxx" -FGAIManager::FGAIManager() { +FGAIManager::FGAIManager() : + cb_ai_bare(SGPropertyChangeCallback(this,&FGAIManager::updateLOD, + fgGetNode("/sim/rendering/static-lod/ai-bare", true))), + cb_ai_detailed(SGPropertyChangeCallback(this,&FGAIManager::updateLOD, + fgGetNode("/sim/rendering/static-lod/ai-detailed", true))) +{ _dt = 0.0; mNumAiModels = 0; @@ -181,6 +186,18 @@ FGAIManager::update(double dt) { thermal_lift_node->setDoubleValue( strength ); // for thermals } +/** update LOD settings of all AI/MP models */ +void +FGAIManager::updateLOD(SGPropertyNode* node) +{ + ai_list_iterator ai_list_itr = ai_list.begin(); + while(ai_list_itr != ai_list.end()) + { + (*ai_list_itr)->updateLOD(); + ++ai_list_itr; + } +} + void FGAIManager::attach(FGAIBase *model) { diff --git a/src/AIModel/AIManager.hxx b/src/AIModel/AIManager.hxx index d08bf17f0..5c951912e 100644 --- a/src/AIModel/AIManager.hxx +++ b/src/AIModel/AIManager.hxx @@ -27,6 +27,7 @@ #include #include +#include #include
@@ -66,6 +67,7 @@ public: void bind(); void unbind(); void update(double dt); + void updateLOD(SGPropertyNode* node); void attach(FGAIBase *model); void destroyObject( int ID ); @@ -135,6 +137,8 @@ private: double strength; void processThermal( FGAIThermal* thermal ); + SGPropertyChangeCallback cb_ai_bare; + SGPropertyChangeCallback cb_ai_detailed; }; #endif // _FG_AIMANAGER_HXX -- 2.39.5