How to traverse the adjacent drawables

16 views
Skip to first unread message

Alveena Rifat

unread,
Apr 18, 2020, 4:45:40 AM4/18/20
to OpenSceneGraph Users
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");
}


 

OpenSceneGraph Users

unread,
Apr 18, 2020, 5:14:32 AM4/18/20
to osg-...@lists.openscenegraph.org

I think the easiest is to give the labels a certain name, then use a NodeVisitor and implement apply(Text3D) checking the name and setting the new font.

OpenSceneGraph Users

unread,
Apr 18, 2020, 12:39:17 PM4/18/20
to OpenSceneGraph Users
One the question "How to access adjacent nodes/drawables?"

All nodes/drawables have a getParents() methods that list all the Node's above it in the scene graph, you can traverse your parents list of children to get all the siblings.


Reply all
Reply to author
Forward
0 new messages