[osg-users] Toggling between wireframe modes

Igor Naigovzin nashnub at gmail.com
Wed Nov 7 07:36:13 PST 2018


Init

    auto scene = new osg::Group;
    auto swtch = new osg::Switch;
    auto scribe = new osgFX::Scribe;
    auto node = osgDB::readNodeFile(......);
    scene->addChild(swtch);
    swtch->addChild(node);
    swtch->addChild(scribe);
    scribe->addChild(node);
    swtch->setSingleChildOn(0);
    viewer->setSceneData(scene);


void enterWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer*
viewer)
{
    osg::Node* scene = viewer->getSceneData();
    osg::Switch* swtch = scene->asGroup()->getChild(0)->asSwitch();
    swtch->setSingleChildOn(1);
}


void exitWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer*
viewer)
{
    osg::Node* scene = viewer->getSceneData();
    osg::Switch* swtch = scene->asGroup()->getChild(0)->asSwitch();
    swtch->setSingleChildOn(0);
}


On Wed, Nov 7, 2018 at 4:50 PM Charlie Tan <chen.qunhan at gmail.com> wrote:

> Hi,
>
> I just began using OSG for one of my projects. Basically one of the tasks
> is to enable/disable wireframe mode. I have tried to follow the
> osgkeyboardmouse example and tried to implement a different version(where
> you don't have to click on the model, but push a keyboard key) to toggle
> between the modes.
>
> To do this, I use 2 functions, enterWireFrame() and exitWireFrame() to
> toggle between the wireframe modes:
>
> void enterWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer*
> viewer)
> {
>   osg::Node* scene = viewer->getSceneData();
>
>   osg::Group* parent = scene->getParent(0);
>   osg::Node* node = parent->getChild(0);
>
>   auto scribe = new osgFX::Scribe();
>   scribe->addChild(node);
>
>   parent->replaceChild(node, scribe);
> }
>
>
>
> void exitWireFrame(const osgGA::GUIEventAdapter& ea, osgViewer::Viewer*
> viewer)
> {
>     osg::Node* scene = viewer->getSceneData();
>
>     osg::Group* parent = scene->getParent(0);
>     osg::Node* node = (dynamic_cast<osg::Group*>(scene))->getChild(0);
>
>     parent->replaceChild(parent, node);
> }
>
>
> I then ran enterWireFrame() followed by exitWireFrame(). I am able to
> render the wireframe after the 1st function, but the 2nd function does not
> do anything at all.
>
> I am totally new to OSG and would very much appreciate if someone could
> point me in the right direction where my mistake lies (probably in the 2nd
> function, but I can't figure it out).
>
> Thank you!
>
> Cheers,
> Charlie
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=75172#75172
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20181107/c4dff178/attachment.html>


More information about the osg-users mailing list