如何使osgEarth::ModelLayer的模型在距离超过某个值时隐藏?
How to make osgEarth::ModelLayer's model hide if distance exceeds some value?
我正在尝试显示模型文件中的标签,osgearth_features
演示展示了如何做到这一点。它对我来说效果很好,但是一旦到地球的距离超过某个值,我需要标签消失。(我使用的是osgEarth的25ce0e1版本。
我知道有PagedLOD
,这将有助于我隐藏osg::Node
。但我所拥有的是osgEarth::ModelLayer
,我似乎找不到一种明智的方式在MapNode
和我的标签之间插入PagedLOD
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 )
这种节点的替换对我来说似乎太丑陋了。实现目标的更好、"正确"的方法是什么?或者这就是这些事情应该做的方式?
也许你可以编写一个带有自定义文件扩展名的伪加载器,用它来包装你的真实模型文件名(如mymodel.obj.plod(,然后"加载"并将PagedLOD重新转换为osgEarth到图形中,在PageLOD子属性中使用"真实"模型路径名。
相关文章:
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 结构和双指针隐藏在其他结构中,多层混淆
- 用C++程序计算圆锥体的体积、球体的体积、八边形的面积和两点之间的距离
- 在 cpp 文件中隐藏采用模板参数引用的方法
- 计算所有对之间的曼哈顿距离
- 如何使用发送数据包所花费的时间计算两个节点之间的距离?
- Levenshtein 两个文件的距离花费了太多时间
- 参数包构造函数在类模板中隐藏用户定义的转换
- 如何等待窗口隐藏在Qt中?
- 如何使用类型别名从模板化类中隐藏模板列表
- 在设计 SDK 时,我是否应该在 C++ 头文件中完全隐藏内部类?
- 名称隐藏对静态函数继承的实例使用
- 两个有符号数字之间的距离
- 计算车辆之间的距离并设置速度,使距离保持不变,例如 5 米
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- 从多个模板化基类派生时出现"隐藏重载的虚函数"警告
- 如何在 Omnet++ 5.6.1 中隐藏箭头?
- 计算两个迭代器之间的距离时"Vector Iterators Incompatible"
- 如何使osgEarth::ModelLayer的模型在距离超过某个值时隐藏?