From 35c24ce5d4ee1276a4bc1f17e42f7ce0a443bb13 Mon Sep 17 00:00:00 2001 From: Dan Wickstrom Date: Sat, 18 May 2019 07:10:40 -0400 Subject: [PATCH] Update radius of AI model after model data is loaded - prevents rendering artifacts at near/far camera boundary. --- src/AIModel/AIBase.cxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 2f1aec7b6..c756d1c18 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -87,6 +87,12 @@ public: _hasInteriorPath = true; } + // save radius of loaded model for updating LOD + auto bs = n->getBound(); + if (bs.valid()) { + _radius = bs.radius(); + } + _fxpath = prop->getStringValue("sound/path"); _nasal[path] = std::unique_ptr(new FGNasalModelDataProxy(_root)); _nasal[path]->modelLoaded(path, prop, n); @@ -106,6 +112,7 @@ public: bool getInteriorLoaded(void) { return _interiorLoaded;} bool hasInteriorPath(void) { return _hasInteriorPath;} inline std::string& getInteriorPath() { return _interiorPath; } + inline float getRadius() { return _radius; } private: std::string _fxpath; std::string _interiorPath; @@ -116,6 +123,7 @@ private: bool _initialized = false; bool _hasInteriorPath = false; bool _interiorLoaded = false; + float _radius = -1.0; SGPropertyNode* _root; }; @@ -288,6 +296,10 @@ void FGAIBase::update(double dt) { // which must be done in main thread _modeldata->init(); + // update LOD radius from loaded modeldata + _model->setRadius(_modeldata->getRadius()); + _model->dirtyBound(); + // sound initialization if (fgGetBool("/sim/sound/aimodels/enabled",false)) {