查看: 1185|回复: 1

osg三维弹窗设计

[复制链接]
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 2020-4-10 09:28:23 | 显示全部楼层 |阅读模式
    本帖最后由 liyihongcug 于 2020-4-10 10:52 编辑

    看到谷歌地图的灵活弹窗(气泡框),osg也是不可或缺的。总体实现如下:
    FeatureGeomModelOptions fgm_opt;
        fgm_opt.featureOptions() = feature_opt;
        fgm_opt.styles() = styleSheet;
        fgm_opt.layout() = layout;

    确实复杂一些,详细设计开发实践整理中,但百分百是OK。 不弱于其他弹窗
    但比起webgl还是弱。
    (比顶点着色 片元着色的js真简单多了。 GLSL不能否认还是难点)

    大体思路StyleSheet
    样式表(这个osg参考是BS )分为脚本语言(js)和样式(css),所以必须分别设置
    脚本 void setScript( ScriptDef* script )    ScriptDef(const std::string& code, const std::string& language="javascript", const std::string& name="") :
                code(code), language(language), name(name) { }
             使用方法
          osg::ref_ptr<osgEarth::Symbology::StyleSheet::ScriptDef> scriptDef = new osgEarth::Symbology::StyleSheet::ScriptDef("function a(){return 1;}","javascript","a");
               .styles()->setScript(scriptDef.get());
    样式  void addStyle( const Style& style ); //这个估计都会用,不说了。
    完美收官
  • TA的每日心情
    开心
    2020-3-20 17:50
  • 签到天数: 1 天

    [LV.1]初来乍到

     楼主| 发表于 2020-4-14 10:15:59 | 显示全部楼层
    参考使用 PlaceNode 就可以。不使用Js ,因为不支持中文。
    所以最后还是后台代码使用来实现
    GeoPoint pntt(osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getSRS(),0.0,0.0, 1000.0, ALTMODE_ABSOLUTE);
        PlaceNode *place = new PlaceNode(mapNode, pntt, "" );
        osg::Group* attachedpoint = place->getAttachPoint();


    //this must be first - boundind box
    {
            osgText::Text* t = new osgText::Text();
            t->setAutoRotateToScreen( false );
            t->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
            t->setCharacterSize( 32.0f );
            //    t->setColor(Color::Yellow );
            t->setBoundingBoxColor( osg::Vec4d(1.0, 1.0, 1.0, 0.5));
            t->setBoundingBoxMargin(3);
            t->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
            t->setDrawMode(1|2|4);
            t->setText("onetwothree\nfour\nfive");
            t->setAlignment(osgText::Text::AlignmentType::RIGHT_CENTER);
            osgText::Font* font= osgText::readFontFile( "fonts/arial.ttf" );
            t->setFont(font);

            osg::Geode* geode = new osg::Geode();
            geode->addDrawable(t);
            osg::StateSet* stateSet = geode->getOrCreateStateSet();
            stateSet->setAttributeAndModes( new osg:epth(osg::Depth::ALWAYS), 1 );
            Registry::shaderGenerator().run(geode);
            attachedpoint->addChild(geode);
        }

    //this must be second
        {
            osgText::Text* t = new osgText::Text();
            t->setAutoRotateToScreen( false );
            t->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
            t->setCharacterSize( 32.0f );
            t->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
            t->setBoundingBoxMargin(0);
            t->setBoundingBoxColor( osg::Vec4d(0.0, 0.0, 0.0, 0.5));
            t->setBackdropColor(osg::Vec4(0.3, 0.3, 0.3, 1));
            t->setBackdropType(osgText::Text::OUTLINE);
            t->setText("onetwothree\nfour\nfive");
            t->setAlignment(osgText::Text::AlignmentType::RIGHT_CENTER);
            osgText::Font* font= osgText::readFontFile( "fonts/arial.ttf" );
            t->setFont(font);
            t->setDrawMode(1|2|4);

            osg::Geode* geode = new osg::Geode();
            geode->addDrawable(t);
            osg::StateSet* stateSet = geode->getOrCreateStateSet();
            stateSet->setAttributeAndModes( new osg::Depth(osg::Depth::ALWAYS), 1 );
            attachedpoint->addChild(geode);
            Registry::shaderGenerator().run(geode);
        }
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    OSG中国官方论坛-有您OSG在中国才更好

    网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

    联系我们

    • 工作时间:09:00--18:00
    • 反馈邮箱:1315785073@qq.com
    快速回复 返回顶部 返回列表