我正在尝试显示模型文件中的标签,osgearth_features
演示显示了如何执行此操作。它对我来说很好,但是一旦到地球的距离超过某个值,我需要标签消失。(我使用的是 osgEarth 的 25ce0e1 版本。)
我知道有PagedLOD
,这将帮助我隐藏一个osg::Node
. 但我所拥有的是osgEarth::ModelLayer
,我似乎找不到在我的标签PagedLOD
之间插入的明智方法。MapNode
Node
我目前的方法,虽然可行,但有点老套。这是对原始 osgearth 的实验性更改,osgearth_features.cpp
以执行我需要的操作:
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 )
这种节点的替换对我来说似乎太难看了。实现我的目标的更好、“正确”的方法是什么?或者这就是这些事情应该做的方式?