From 3235f4fa22da96d82879d532cc797c0eebfbe498 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Jan 2006 16:52:06 +0000 Subject: [PATCH] Added ability to write out the selected parts of the scene graph. --- .../osgkeyboardmouse/osgkeyboardmouse.cpp | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/examples/osgkeyboardmouse/osgkeyboardmouse.cpp b/examples/osgkeyboardmouse/osgkeyboardmouse.cpp index 047e4680d..d00c461dc 100644 --- a/examples/osgkeyboardmouse/osgkeyboardmouse.cpp +++ b/examples/osgkeyboardmouse/osgkeyboardmouse.cpp @@ -14,10 +14,42 @@ #include #include +#include #include +class CreateModelToSaveVisitor : public osg::NodeVisitor +{ +public: + + CreateModelToSaveVisitor(): + osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) + { + _group = new osg::Group; + _addToModel = false; + } + + virtual void apply(osg::Node& node) + { + osgFX::Scribe* scribe = dynamic_cast(&node); + if (scribe) + { + for(unsigned int i=0; igetNumChildren(); ++i) + { + _group->addChild(scribe->getChild(i)); + } + } + else + { + traverse(node); + } + } + + osg::ref_ptr _group; + bool _addToModel; +}; + class MyKeyboardMouseCallback : public Producer::KeyboardMouseCallback { public: @@ -47,6 +79,7 @@ public: virtual void keyPress( Producer::KeyCharacter key) { if (key==' ') resetTrackball(); + else if (key=='o') saveSelectedModel(); } virtual void mouseMotion( float mx, float my ) @@ -185,6 +218,17 @@ public: } + void saveSelectedModel() + { + CreateModelToSaveVisitor cmtsv; + _sceneView->getSceneData()->accept(cmtsv); + + if (cmtsv._group->getNumChildren()>0) + { + osgDB::writeNodeFile(*cmtsv._group, "selected_model.osg"); + } + } + private: float _mx, _my;