]> git.mxchange.org Git - flightgear.git/commitdiff
Add LOD to each AI model
authorTorsten Dreyer <Torsten@t3r.de>
Tue, 9 Aug 2011 16:02:37 +0000 (18:02 +0200)
committerTorsten Dreyer <Torsten@t3r.de>
Tue, 9 Aug 2011 16:02:37 +0000 (18:02 +0200)
Add a LOD (range animation) to each AI model if the property
/sim/rendering/static-lod/ai is set to any number greater than
zero. AI models get loaded but only displayed when closer than
the number given in the property (in meters).
If the property is absent or it's value is less or equal 0.0
than no LOD is added to the AI model.

src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx

index ac907c2e383e5263546dfa30df4f62493e9a3a54..8a8e1c8f31eec673924c9ee49a5d19d910f2c8d9 100644 (file)
@@ -225,8 +225,22 @@ bool FGAIBase::init(bool search_in_AI_path) {
     else
         _installed = true;
 
-    model = load3DModel(f, props);
+    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");
+
+        lod->addChild( mdl, 0, aiModelMaxRange );
+        lod->setCenterMode(osg::LOD::USE_BOUNDING_SPHERE_CENTER);
+        lod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT);
+
+        model = lod;
+    }
+
+    initModel(mdl);
     if (model.valid() && _initialized == false) {
         aip.init( model.get() );
         aip.setVisible(true);
@@ -266,13 +280,6 @@ void FGAIBase::initModel(osg::Node *node)
 }
 
 
-osg::Node* FGAIBase::load3DModel(const string &path, SGPropertyNode *prop_root)
-{
-  model = SGModelLib::loadPagedModel(path, prop_root, new FGNasalModelData(prop_root));
-  initModel(model.get());
-  return model.get();
-}
-
 bool FGAIBase::isa( object_type otype ) {
     return otype == _otype;
 }
index afedabc3f73c50889c903240baebe6565ad4377d..fa85d5d2b656ab066311caf672ec4ceac73167f1 100644 (file)
@@ -300,9 +300,6 @@ public:
     inline double _getRange() { return range; };
     inline double _getBearing() { return bearing; };
 
-    virtual osg::Node* load3DModel(const string &path,
-        SGPropertyNode *prop_root);
-
     static bool _isNight();
 
      string & getCallSign();