OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Toggling between wireframe modes


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
charlietan789
Newbie


Joined: 07 Nov 2018
Posts: 5

PostPosted: Wed Nov 07, 2018 9:41 am    Post subject:
Toggling between wireframe modes
Reply with quote

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
Back to top
View user's profile Send private message
Igor Naigovzin
Guest





PostPosted: Wed Nov 07, 2018 3:37 pm    Post subject:
Toggling between wireframe modes
Reply with quote

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 < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:

Quote:
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
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


------------------
Post generated by Mail2Forum
Back to top
charlietan789
Newbie


Joined: 07 Nov 2018
Posts: 5

PostPosted: Thu Nov 08, 2018 5:18 am    Post subject:
Reply with quote

Thanks it works perfectly!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts wireframe darker wrt the surface color gambr General 10 Tue Mar 21, 2017 4:00 pm View latest post
No new posts wireframe mode and degenerate triangles cbuchner1 General 1 Fri Dec 30, 2016 1:39 pm View latest post
No new posts WireFrame display for 3d model using ... umadevi2193 General 1 Sat Sep 24, 2016 7:12 am View latest post
No new posts Texture modes in OpenGL ES 2.0 in OSG Sergey Kurdakov General 4 Tue Sep 09, 2014 9:34 am View latest post
No new posts wireframe gambr General 8 Mon Aug 25, 2014 10:54 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP