Added ability to write out the selected parts of the scene graph.
This commit is contained in:
@@ -14,10 +14,42 @@
|
||||
#include <osgUtil/IntersectVisitor>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgDB/WriteFile>
|
||||
|
||||
#include <osgFX/Scribe>
|
||||
|
||||
|
||||
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<osgFX::Scribe*>(&node);
|
||||
if (scribe)
|
||||
{
|
||||
for(unsigned int i=0; i<scribe->getNumChildren(); ++i)
|
||||
{
|
||||
_group->addChild(scribe->getChild(i));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
traverse(node);
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Group> _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;
|
||||
|
||||
Reference in New Issue
Block a user