[osg-users] How to traverse the adjacent drawables

OpenSceneGraph Users osg-users at lists.openscenegraph.org
Sat Apr 18 00:54:24 PDT 2020


I want to set the font of the axes labels(X,Y,Z) using GUI so I traverse 
through the scenegraph, to access the axis labels(X,Y,Z) which are text3D 
nodes. The function getLabelText3D(..) returns the drawables as text3D and 
later set the font of the drawable  by setFont() but the font style only 
gets applied on X label but not Y,Z. Now how do I access the remaining 
drawables.


osgText::Text3D* AxesNode::getLabelText3D(::osg::Node* axes)
    {
        osg::Switch *switch_node = getLabelSwitch(axes);   // returns the 
switch node which has the Geode to which X,Y,Z text3D nodes are added as 
drawables.
        if(!switch_node)
        {
            return NULL;
        }

        osg::Node* node = switch_node->getChild(0);
        osg::Geode* geode_node = node->asGeode();
        if(geode_node && geode_node->getNumDrawables() > 1)
        {
            for(osg::Drawable* drawable : geode_node->getDrawableList())
            {
                osgText::Text3D* text = 
dynamic_cast<osgText::Text3D*>(drawable);  //here I have three drawables 
X,Y,Z but the function only returns X drawable
                if(text)
                {
                    return text;
                }
            }
        }
        return NULL;
    }



void Vizkit3DWidget::setFont(....)
{
      
      osg::Node *node = FindNode::find(*getRootNode(),"axes_node");
         
        osgText::Text3D*  text3d = 
AxesNode::getLabelText3D(switch_node->getChild(0));
    
        text3d->setFont(font_d.get());                //only sets font for 
X label, no effect on Y,Z label
 
emit propertyChanged("font");
}


 

-- 
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+unsubscribe at googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/3f457cd4-2760-45a9-a376-361612aa312f%40googlegroups.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20200418/698750ed/attachment.html>


More information about the osg-users mailing list