osg三维弹窗设计
本帖最后由 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 ); //这个估计都会用,不说了。
完美收官 参考使用 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::Depth(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);
}
页:
[1]