Discussion:
[osg-users] Toggling between wireframe modes
Charlie Tan
2018-11-07 09:41:44 UTC
Permalink
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
Igor Naigovzin
2018-11-07 15:36:13 UTC
Permalink
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);
}
Post by Charlie Tan
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
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
------------------
http://forum.openscenegraph.org/viewtopic.php?p=75172#75172
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Charlie Tan
2018-11-08 05:18:48 UTC
Permalink
Thanks it works perfectly!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75174#75174

Loading...