I'm trying to display labels from a model file, and the osgearth_features
demo shows how to do this. It works fine for me, but I need the labels to disappear once the distance to the Earth exceeds some value. (I'm using version 25ce0e1 of osgEarth.)
I know that there is PagedLOD
, which would help me with hiding an osg::Node
. But what I have is osgEarth::ModelLayer
, and I can't seem to find a sensible way to insert PagedLOD
between MapNode
and my labels Node
.
My current approach, albeit workable, is somewhat hacky. Here's an experimental change to the original osgearth's osgearth_features.cpp
to do what I need:
diff --git a/src/applications/osgearth_features/osgearth_features.cpp b/src/applications/osgearth_features/osgearth_features.cpp
index 2bb1ed8..fbdd3da 100644
--- a/src/applications/osgearth_features/osgearth_features.cpp
+++ b/src/applications/osgearth_features/osgearth_features.cpp
@@ -184,6 +184,12 @@ int main(int argc, char** argv)
geomOptions.styles()->addStyle( labelStyle );
map->addModelLayer( new ModelLayer("labels", geomOptions) );
+ osg::Group*const modelLayerGroup=mapNode->getModelLayerGroup();
+ const int newNumChildren=modelLayerGroup->getNumChildren();
+ osg::Node*const model=modelLayerGroup->getChild(newNumChildren-1);
+ osg::PagedLOD*const lod=new osg::PagedLOD;
+ modelLayerGroup->replaceChild(model,lod);
+ lod->addChild(model, 0, 1e7);
}
if ( !useStencil )
This replacement of nodes seems too ugly to me. What is the better, "correct" way to achieve my goal? Or this is the way such things are supposed to be done?