【osgEarth】Mac系统下开发osgEarth注意事项

1 篇文章 0 订阅
1 篇文章 0 订阅

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


编译osgEarth

提示:对应的OSG库也需要编译OpenGL3版本的:

编译最新的osgEarth库(>=3.0版本)需要编译OpenGL3可编程渲染管线。
https://gist.github.com/gwaldron/a56b0e77e7fa8587b698717d21f9366d
本文以OSG3.6.5和OSGEarth3.4为例介绍一些注意事项


提示:以下是本篇文章正文内容,下面案例可供参考

一、如何接入全球影像服务?

OpenStreetMap影像地址
https://b.tile.openstreetmap.org/0/0/0.png
在这里插入图片描述

Google影像地址
https://mt.google.com/vt/lyrs=y&x=0&y=0&z=0
在这里插入图片描述
加载谷歌地图的时候不同lyrs表示的地图类型如下

  • m 标准路线图
  • r 某种改变的路线图(路线不明显)
  • s 影像卫星图
  • y 带标签的卫星图
  • h 标签层 (路名、地名等)
  • t 地形图
  • p 带标签的地形图

二、使用插件注意事项

因为Mac系统下默认的图片解析库是ImageIO,但ImageIO库的使用有很多问题

1. ImageIO插件读TIF不能生成地形,读TIF要使用TIFF插件或GDAL插件

使用HTTPClient读TIF生成地形用TIFF插件:

auto registry = osgDB::Registry::instance();
registry->addFileExtensionAlias("tif", "tiff");

使用osgDB::readImage读tif生成地形使用gdal插件:

auto registry = osgDB::Registry::instance();
registry->addFileExtensionAlias("tif", "gdal");

2.ImageIO读jpeg有误,pixelFormat读成了GL_BGRA而不是RGBA:

使用osgDB::writeImageFile写jpeg时要切换jpeg插件

auto registry = osgDB::Registry::instance();
registry->addFileExtensionAlias("jpeg", "jpeg");

三、调整看见瓦片的更新速度

MapNode::Options options;
options.terrain()->minTileRangeFactor() = 9.0;
MapNode* mapNode = new MapNode( map , options);

四、天空盒

osgEarth::SimpleSky::SimpleSkyOptions simpleSkyOptions;
simpleSkyOptions.moonImageURI() = URI("data/moon_1024x512.jpg");
auto skyNode = SkyNode::create(simpleSkyOptions);
mapNode->addChild(skyNode);

五、接入Mac系统的触控板

修改GraphicsWindowCocoaGLView中以下两个函数

  • mouseScroll2D需要传入scrollingDeltaX和scrollingDeltaY
  • 添加magnifyWithEvent
- (void) scrollWheel:(NSEvent*)theEvent
{
    if (!_win) return;

    // Unfortunately, it turns out mouseScroll2D doesn't actually do anything.
    // The camera manipulators don't seem to implement any code that utilize the scroll values.
    // This this call does nothing.
    _win->getEventQueue()->mouseScroll2D([theEvent scrollingDeltaX], [theEvent scrollingDeltaY]);
}

- (void) magnifyWithEvent:(NSEvent *)theEvent
{
    if (!_win) return;
    _win->getEventQueue()->penPressure(theEvent.magnification);
}

修改自定义Handler

	auto earthManip = dynamic_cast<osgEarth::EarthManipulator*>(view->getCameraManipulator());
    if (earthManip) {
        if (ea.getEventType() == osgGA::GUIEventAdapter::SCROLL) {
            auto ratio = 0.01;
            if (fabs(ea.getScrollingDeltaX()) > fabs(ea.getScrollingDeltaY())) {
                earthManip->rotate(ea.getScrollingDeltaX() * ratio , 0);
            } else {
                earthManip->rotate(0 , -ea.getScrollingDeltaY() * ratio);
            }
        } else if (ea.getEventType() == osgGA::GUIEventAdapter::PEN_PRESSURE) {
            earthManip->setDistance(earthManip->getDistance() * (1.0 - ea.getPenPressure()));
        }
    }

六、解决z-fighting

    auto test1 = GeometryUtils::createUnitQuadGeode(osg::Vec4f(1.0, 0.0, 0.0, 1.0));
    auto test2 = GeometryUtils::createUnitQuadGeode(osg::Vec4f(1.0, 1.0, 0.0, 1.0));
    auto mt1 = new osg::MatrixTransform;
    mt1->setMatrix(MathExtension::computeWorldMatrix(osg::Vec3d(110, 30, 100000), osg::Vec3d(0, 0, 0), osg::Vec3d(500000, 500000, 500000)));
    mt1->addChild(test1);
    auto mt2 = new osg::MatrixTransform;
    mt2->setMatrix(MathExtension::computeWorldMatrix(osg::Vec3d(112, 30, 100000), osg::Vec3d(0, 0, 0), osg::Vec3d(500000, 500000, 500000)));
    mt2->addChild(test2);
    auto depthOffsetGroup = new DepthOffsetGroup;
    depthOffsetGroup->addChild(mt1);
    depthOffsetGroup->addChild(mt2);
    mapNode->addChild(depthOffsetGroup);

七、解决LineSymbol、SkinSymbol未显示

为LineSymbol设置stipplePattern

ls->stroke()->stipplePattern() = 0xFFFF;

为SkinSymbol要设置正确的heightExpression和tag,tag和高度范围同时决定ExtrusionSymbol用什么纹理

Style buildingStyle;
    buildingStyle.setName( "default" );
    osgEarth::ExtrusionSymbol* symbol = buildingStyle.getOrCreate<osgEarth::ExtrusionSymbol>();
    symbol->heightExpression() = NumericExpression( "150" );
    symbol->flatten() = true;
    symbol->wallStyleName() = "building-wall";
    symbol->roofStyleName() = "building-roof";
Style wallStyle;
    wallStyle.setName( "building-wall" );
    SkinSymbol* wallSkin = wallStyle.getOrCreate<SkinSymbol>();
    wallSkin->library() = "us_resources";
    wallSkin->addTag( "building" );
    wallSkin->randomSeed() = 3;
    wallSkin->isTiled() = false;


<skin name="3stStorefront" tags="building commercial us storefront concrete">
        <url>commercial/3storystorefronttown.jpg</url>
        <image_width>9</image_width>
        <min_object_height>7</min_object_height>
        <max_object_height>12</max_object_height>
        <tiled>false</tiled>
    </skin>

八、解决在节点回调中修改buffer导致程序崩溃的问题

调用dirtyGLObjects函数

m_pFillDrawable->dirtyGLObjects();

总结

以上就是今天要讲的内容,本文仅仅简单介绍了Mac系统下开发osgEarth的一些注意事项,是作者自己在踩了很多坑的情况总结出来的经验教训,希望能对大家有所帮助。
最后附上一些效果图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 21
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值